From 207b5e2de1d0b6378f958f0ed9a47b0d12b46917 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 21 Jan 2021 15:42:10 +0000 Subject: [PATCH] Move tint::ast::type to tint::type Despite `tint::ast::type::Type` being in the AST namespace, these classes are clearly not AST nodes: * They don't derive from ast::Node * They're deduplicated by the type manager * None of the types have an Source - they have no lexical declaration point * The fact we have `ast::Struct` and `ast::type::Struct` clearly demonstrates what is an AST node, and what is a type. * We have code scattered in the codebase (TypeDeterminer, writers, etc) that create new types after parsing - so clearly not part of the original syntax tree. Types in tint are closer to being semantic info, but due to the parse-time generation of types, and tight dependency of ast::Nodes to types, I'd be reluctant to class these as semantic info. Instead, put these into a separate root level `tint::type` namespace and `src/tint` directory. The fact that types exist in the ast::Module has already caused bugs (https://dawn-review.googlesource.com/c/tint/+/37261). This is a first step in separating out types from the ast::Module. Bug: tint:390 Change-Id: I8349bbbd1b19597b8e6d51d5cda0890de46ecaec Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38002 Commit-Queue: Ben Clayton Reviewed-by: dan sinclair --- BUILD.gn | 116 ++-- fuzzers/tint_ast_clone_fuzzer.cc | 2 +- include/tint/tint.h | 2 +- src/CMakeLists.txt | 138 ++--- src/ast/bitcast_expression.h | 2 +- src/ast/bitcast_expression_test.cc | 2 +- src/ast/bool_literal_test.cc | 2 +- src/ast/builder.h | 22 +- src/ast/case_statement_test.cc | 4 +- src/ast/else_statement_test.cc | 2 +- src/ast/expression.h | 2 +- src/ast/expression_test.cc | 4 +- src/ast/float_literal_test.cc | 2 +- src/ast/function.cc | 6 +- src/ast/function.h | 4 +- src/ast/int_literal_test.cc | 4 +- src/ast/intrinsic_texture_helper_test.cc | 108 ++-- src/ast/intrinsic_texture_helper_test.h | 8 +- src/ast/literal.h | 2 +- src/ast/module.cc | 2 +- src/ast/module.h | 6 +- src/ast/module_clone_test.cc | 2 +- src/ast/module_test.cc | 6 +- src/ast/node.h | 7 +- src/ast/null_literal_test.cc | 2 +- src/ast/scalar_constructor_expression_test.cc | 2 +- src/ast/sint_literal_test.cc | 4 +- src/ast/struct_member.h | 2 +- src/ast/struct_member_test.cc | 2 +- src/ast/struct_test.cc | 2 +- src/ast/switch_statement_test.cc | 2 +- src/ast/type_constructor_expression.h | 2 +- src/ast/type_constructor_expression_test.cc | 4 +- src/ast/uint_literal_test.cc | 2 +- src/ast/variable.h | 2 +- src/ast/variable_decl_statement_test.cc | 2 +- src/ast/variable_test.cc | 4 +- src/inspector/inspector.cc | 78 ++- src/inspector/inspector_test.cc | 320 +++++----- src/reader/spirv/enum_converter.cc | 58 +- src/reader/spirv/enum_converter.h | 8 +- src/reader/spirv/enum_converter_test.cc | 141 ++--- src/reader/spirv/function.cc | 130 ++-- src/reader/spirv/function.h | 12 +- src/reader/spirv/parser_impl.cc | 357 ++++++----- src/reader/spirv/parser_impl.h | 68 +-- .../spirv/parser_impl_convert_type_test.cc | 258 ++++---- .../spirv/parser_impl_named_types_test.cc | 8 +- src/reader/wgsl/parser_impl.cc | 272 ++++----- src/reader/wgsl/parser_impl.h | 61 +- .../wgsl/parser_impl_const_expr_test.cc | 6 +- .../parser_impl_depth_texture_type_test.cc | 30 +- .../wgsl/parser_impl_function_decl_test.cc | 20 +- .../wgsl/parser_impl_function_header_test.cc | 6 +- .../parser_impl_function_type_decl_test.cc | 12 +- .../parser_impl_global_constant_decl_test.cc | 4 +- .../wgsl/parser_impl_global_decl_test.cc | 36 +- .../parser_impl_global_variable_decl_test.cc | 10 +- .../parser_impl_image_storage_type_test.cc | 72 +-- .../wgsl/parser_impl_param_list_test.cc | 14 +- .../parser_impl_primary_expression_test.cc | 8 +- .../parser_impl_sampled_texture_type_test.cc | 30 +- .../wgsl/parser_impl_sampler_type_test.cc | 10 +- .../parser_impl_storage_texture_type_test.cc | 52 +- .../wgsl/parser_impl_struct_body_decl_test.cc | 4 +- .../wgsl/parser_impl_struct_decl_test.cc | 2 +- .../wgsl/parser_impl_struct_member_test.cc | 8 +- src/reader/wgsl/parser_impl_test.cc | 2 +- .../parser_impl_texture_sampler_types_test.cc | 185 +++--- .../wgsl/parser_impl_type_alias_test.cc | 26 +- src/reader/wgsl/parser_impl_type_decl_test.cc | 135 ++-- .../wgsl/parser_impl_variable_decl_test.cc | 6 +- .../parser_impl_variable_ident_decl_test.cc | 34 +- src/scope_stack_test.cc | 2 +- src/transform/bound_array_accessors.cc | 22 +- src/transform/emit_vertex_point_size.cc | 6 +- src/transform/first_index_offset.cc | 14 +- src/transform/vertex_pulling.cc | 32 +- src/transform/vertex_pulling.h | 8 +- src/{ast => }/type/access_control_type.cc | 6 +- src/{ast => }/type/access_control_type.h | 10 +- .../type/access_control_type_test.cc | 50 +- src/{ast => }/type/alias_type.cc | 6 +- src/{ast => }/type/alias_type.h | 10 +- src/{ast => }/type/alias_type_test.cc | 68 +-- src/{ast => }/type/array_type.cc | 14 +- src/{ast => }/type/array_type.h | 16 +- src/{ast => }/type/array_type_test.cc | 53 +- src/{ast => }/type/bool_type.cc | 6 +- src/{ast => }/type/bool_type.h | 10 +- src/{ast => }/type/bool_type_test.cc | 26 +- src/{ast => }/type/depth_texture_type.cc | 6 +- src/{ast => }/type/depth_texture_type.h | 10 +- src/{ast => }/type/depth_texture_type_test.cc | 30 +- src/{ast => }/type/f32_type.cc | 6 +- src/{ast => }/type/f32_type.h | 10 +- src/{ast => }/type/f32_type_test.cc | 26 +- src/{ast => }/type/i32_type.cc | 6 +- src/{ast => }/type/i32_type.h | 10 +- src/{ast => }/type/i32_type_test.cc | 26 +- src/{ast => }/type/matrix_type.cc | 12 +- src/{ast => }/type/matrix_type.h | 10 +- src/{ast => }/type/matrix_type_test.cc | 26 +- .../type/multisampled_texture_type.cc | 6 +- .../type/multisampled_texture_type.h | 10 +- .../type/multisampled_texture_type_test.cc | 32 +- src/{ast => }/type/pointer_type.cc | 8 +- src/{ast => }/type/pointer_type.h | 16 +- src/{ast => }/type/pointer_type_test.cc | 34 +- src/{ast => }/type/sampled_texture_type.cc | 6 +- src/{ast => }/type/sampled_texture_type.h | 10 +- .../type/sampled_texture_type_test.cc | 30 +- src/{ast => }/type/sampler_type.cc | 6 +- src/{ast => }/type/sampler_type.h | 10 +- src/{ast => }/type/sampler_type_test.cc | 28 +- src/{ast => }/type/storage_texture_type.cc | 6 +- src/{ast => }/type/storage_texture_type.h | 13 +- .../type/storage_texture_type_test.cc | 30 +- src/{ast => }/type/struct_type.cc | 14 +- src/{ast => }/type/struct_type.h | 10 +- src/{ast => }/type/struct_type_test.cc | 147 ++--- src/type/test_helper.h | 52 ++ src/{ast => }/type/texture_type.cc | 10 +- src/{ast => }/type/texture_type.h | 10 +- src/{ast => }/type/texture_type_test.cc | 6 +- src/{ast => }/type/type.cc | 34 +- src/{ast => }/type/type.h | 16 +- src/{ast => type}/type_manager.cc | 18 +- src/{ast => type}/type_manager.h | 26 +- src/{ast => type}/type_manager_test.cc | 41 +- src/{ast => }/type/u32_type.cc | 6 +- src/{ast => }/type/u32_type.h | 10 +- src/{ast => }/type/u32_type_test.cc | 28 +- src/{ast => }/type/vector_type.cc | 6 +- src/{ast => }/type/vector_type.h | 10 +- src/{ast => }/type/vector_type_test.cc | 26 +- src/{ast => }/type/void_type.cc | 6 +- src/{ast => }/type/void_type.h | 10 +- src/type_determiner.cc | 247 ++++---- src/type_determiner.h | 14 +- src/type_determiner_test.cc | 578 ++++++++---------- src/validator/validator_control_block_test.cc | 8 +- src/validator/validator_function_test.cc | 6 +- src/validator/validator_impl.cc | 53 +- src/validator/validator_impl.h | 5 +- src/validator/validator_test.cc | 20 +- src/validator/validator_test_helper.h | 2 +- src/validator/validator_type_test.cc | 10 +- src/writer/append_vector.cc | 10 +- src/writer/hlsl/generator_impl.cc | 235 ++++--- src/writer/hlsl/generator_impl.h | 12 +- .../hlsl/generator_impl_alias_type_test.cc | 2 +- .../generator_impl_array_accessor_test.cc | 2 +- src/writer/hlsl/generator_impl_binary_test.cc | 14 +- .../hlsl/generator_impl_bitcast_test.cc | 6 +- src/writer/hlsl/generator_impl_call_test.cc | 2 +- src/writer/hlsl/generator_impl_case_test.cc | 2 +- src/writer/hlsl/generator_impl_cast_test.cc | 4 +- .../hlsl/generator_impl_constructor_test.cc | 14 +- .../hlsl/generator_impl_function_test.cc | 24 +- src/writer/hlsl/generator_impl_import_test.cc | 8 +- .../hlsl/generator_impl_intrinsic_test.cc | 4 +- .../generator_impl_intrinsic_texture_test.cc | 6 +- src/writer/hlsl/generator_impl_loop_test.cc | 2 +- .../generator_impl_member_accessor_test.cc | 72 +-- .../generator_impl_module_constant_test.cc | 4 +- src/writer/hlsl/generator_impl_switch_test.cc | 2 +- src/writer/hlsl/generator_impl_test.cc | 2 +- src/writer/hlsl/generator_impl_type_test.cc | 182 +++--- ...rator_impl_variable_decl_statement_test.cc | 8 +- src/writer/msl/generator_impl.cc | 217 ++++--- src/writer/msl/generator_impl.h | 14 +- .../msl/generator_impl_alias_type_test.cc | 2 +- .../msl/generator_impl_array_accessor_test.cc | 2 +- src/writer/msl/generator_impl_bitcast_test.cc | 2 +- src/writer/msl/generator_impl_call_test.cc | 2 +- src/writer/msl/generator_impl_case_test.cc | 2 +- src/writer/msl/generator_impl_cast_test.cc | 4 +- .../msl/generator_impl_constructor_test.cc | 16 +- ...tor_impl_function_entry_point_data_test.cc | 8 +- .../msl/generator_impl_function_test.cc | 24 +- src/writer/msl/generator_impl_import_test.cc | 8 +- .../msl/generator_impl_intrinsic_test.cc | 4 +- .../generator_impl_intrinsic_texture_test.cc | 6 +- src/writer/msl/generator_impl_loop_test.cc | 2 +- .../generator_impl_module_constant_test.cc | 4 +- src/writer/msl/generator_impl_switch_test.cc | 2 +- src/writer/msl/generator_impl_test.cc | 32 +- src/writer/msl/generator_impl_type_test.cc | 101 ++- ...rator_impl_variable_decl_statement_test.cc | 12 +- src/writer/spirv/builder.cc | 391 ++++++------ src/writer/spirv/builder.h | 41 +- .../spirv/builder_accessor_expression_test.cc | 22 +- src/writer/spirv/builder_assign_test.cc | 8 +- .../spirv/builder_binary_expression_test.cc | 12 +- .../spirv/builder_bitcast_expression_test.cc | 4 +- src/writer/spirv/builder_block_test.cc | 2 +- src/writer/spirv/builder_call_test.cc | 6 +- .../builder_constructor_expression_test.cc | 16 +- .../spirv/builder_format_conversion_test.cc | 76 ++- src/writer/spirv/builder_function_test.cc | 12 +- .../spirv/builder_function_variable_test.cc | 8 +- .../spirv/builder_global_variable_test.cc | 44 +- .../spirv/builder_ident_expression_test.cc | 6 +- src/writer/spirv/builder_if_test.cc | 4 +- src/writer/spirv/builder_intrinsic_test.cc | 32 +- .../spirv/builder_intrinsic_texture_test.cc | 8 +- src/writer/spirv/builder_literal_test.cc | 8 +- src/writer/spirv/builder_loop_test.cc | 2 +- src/writer/spirv/builder_return_test.cc | 4 +- src/writer/spirv/builder_switch_test.cc | 4 +- src/writer/spirv/builder_type_test.cc | 156 ++--- .../spirv/builder_unary_op_expression_test.cc | 8 +- src/writer/wgsl/generator_impl.cc | 102 ++-- src/writer/wgsl/generator_impl.h | 14 +- .../wgsl/generator_impl_alias_type_test.cc | 2 +- .../generator_impl_array_accessor_test.cc | 2 +- .../wgsl/generator_impl_bitcast_test.cc | 2 +- src/writer/wgsl/generator_impl_case_test.cc | 2 +- src/writer/wgsl/generator_impl_cast_test.cc | 2 +- .../wgsl/generator_impl_constructor_test.cc | 14 +- .../wgsl/generator_impl_function_test.cc | 10 +- src/writer/wgsl/generator_impl_switch_test.cc | 2 +- src/writer/wgsl/generator_impl_test.cc | 2 +- src/writer/wgsl/generator_impl_type_test.cc | 222 ++++--- ...rator_impl_variable_decl_statement_test.cc | 2 +- .../wgsl/generator_impl_variable_test.cc | 2 +- 227 files changed, 3647 insertions(+), 3869 deletions(-) rename src/{ast => }/type/access_control_type.cc (92%) rename src/{ast => }/type/access_control_type.h (92%) rename src/{ast => }/type/access_control_type_test.cc (79%) rename src/{ast => }/type/alias_type.cc (91%) rename src/{ast => }/type/alias_type.h (92%) rename src/{ast => }/type/alias_type_test.cc (79%) rename src/{ast => }/type/array_type.cc (89%) rename src/{ast => }/type/array_type.h (87%) rename src/{ast => }/type/array_type_test.cc (70%) rename src/{ast => }/type/bool_type.cc (88%) rename src/{ast => }/type/bool_type.h (86%) rename src/{ast => }/type/bool_type_test.cc (74%) rename src/{ast => }/type/depth_texture_type.cc (91%) rename src/{ast => }/type/depth_texture_type.h (86%) rename src/{ast => }/type/depth_texture_type_test.cc (76%) rename src/{ast => }/type/f32_type.cc (90%) rename src/{ast => }/type/f32_type.h (90%) rename src/{ast => }/type/f32_type_test.cc (75%) rename src/{ast => }/type/i32_type.cc (90%) rename src/{ast => }/type/i32_type.h (90%) rename src/{ast => }/type/i32_type_test.cc (75%) rename src/{ast => }/type/matrix_type.cc (86%) rename src/{ast => }/type/matrix_type.h (92%) rename src/{ast => }/type/matrix_type_test.cc (87%) rename src/{ast => }/type/multisampled_texture_type.cc (89%) rename src/{ast => }/type/multisampled_texture_type.h (86%) rename src/{ast => }/type/multisampled_texture_type_test.cc (78%) rename src/{ast => }/type/pointer_type.cc (85%) rename src/{ast => }/type/pointer_type.h (80%) rename src/{ast => }/type/pointer_type_test.cc (67%) rename src/{ast => }/type/sampled_texture_type.cc (90%) rename src/{ast => }/type/sampled_texture_type.h (87%) rename src/{ast => }/type/sampled_texture_type_test.cc (78%) rename src/{ast => }/type/sampler_type.cc (91%) rename src/{ast => }/type/sampler_type.h (90%) rename src/{ast => }/type/sampler_type_test.cc (79%) rename src/{ast => }/type/storage_texture_type.cc (96%) rename src/{ast => }/type/storage_texture_type.h (88%) rename src/{ast => }/type/storage_texture_type_test.cc (85%) rename src/{ast => }/type/struct_type.cc (89%) rename src/{ast => }/type/struct_type.h (92%) rename src/{ast => }/type/struct_type_test.cc (51%) create mode 100644 src/type/test_helper.h rename src/{ast => }/type/texture_type.cc (91%) rename src/{ast => }/type/texture_type.h (91%) rename src/{ast => }/type/texture_type_test.cc (94%) rename src/{ast => }/type/type.cc (79%) rename src/{ast => }/type/type.h (94%) rename src/{ast => type}/type_manager.cc (70%) rename src/{ast => type}/type_manager.h (82%) rename src/{ast => type}/type_manager_test.cc (62%) rename src/{ast => }/type/u32_type.cc (90%) rename src/{ast => }/type/u32_type.h (90%) rename src/{ast => }/type/u32_type_test.cc (74%) rename src/{ast => }/type/vector_type.cc (92%) rename src/{ast => }/type/vector_type.h (91%) rename src/{ast => }/type/vector_type_test.cc (82%) rename src/{ast => }/type/void_type.cc (88%) rename src/{ast => }/type/void_type.h (86%) diff --git a/BUILD.gn b/BUILD.gn index 45ceb5e8f8..18beefc4eb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -337,50 +337,10 @@ source_set("libtint_core_src") { "src/ast/switch_statement.cc", "src/ast/switch_statement.h", "src/ast/traits.h", - "src/ast/type/access_control_type.cc", - "src/ast/type/access_control_type.h", - "src/ast/type/alias_type.cc", - "src/ast/type/alias_type.h", - "src/ast/type/array_type.cc", - "src/ast/type/array_type.h", - "src/ast/type/bool_type.cc", - "src/ast/type/bool_type.h", - "src/ast/type/depth_texture_type.cc", - "src/ast/type/depth_texture_type.h", - "src/ast/type/f32_type.cc", - "src/ast/type/f32_type.h", - "src/ast/type/i32_type.cc", - "src/ast/type/i32_type.h", - "src/ast/type/matrix_type.cc", - "src/ast/type/matrix_type.h", - "src/ast/type/multisampled_texture_type.cc", - "src/ast/type/multisampled_texture_type.h", - "src/ast/type/pointer_type.cc", - "src/ast/type/pointer_type.h", - "src/ast/type/sampled_texture_type.cc", - "src/ast/type/sampled_texture_type.h", - "src/ast/type/sampler_type.cc", - "src/ast/type/sampler_type.h", - "src/ast/type/storage_texture_type.cc", - "src/ast/type/storage_texture_type.h", - "src/ast/type/struct_type.cc", - "src/ast/type/struct_type.h", - "src/ast/type/texture_type.cc", - "src/ast/type/texture_type.h", - "src/ast/type/type.cc", - "src/ast/type/type.h", - "src/ast/type/u32_type.cc", - "src/ast/type/u32_type.h", - "src/ast/type/vector_type.cc", - "src/ast/type/vector_type.h", - "src/ast/type/void_type.cc", - "src/ast/type/void_type.h", "src/ast/type_constructor_expression.cc", "src/ast/type_constructor_expression.h", "src/ast/type_decoration.cc", "src/ast/type_decoration.h", - "src/ast/type_manager.cc", - "src/ast/type_manager.h", "src/ast/uint_literal.cc", "src/ast/uint_literal.h", "src/ast/unary_op.cc", @@ -439,6 +399,46 @@ source_set("libtint_core_src") { "src/type_determiner.h", "src/validator/validator.cc", "src/validator/validator.h", + "src/type/access_control_type.cc", + "src/type/access_control_type.h", + "src/type/alias_type.cc", + "src/type/alias_type.h", + "src/type/array_type.cc", + "src/type/array_type.h", + "src/type/bool_type.cc", + "src/type/bool_type.h", + "src/type/depth_texture_type.cc", + "src/type/depth_texture_type.h", + "src/type/f32_type.cc", + "src/type/f32_type.h", + "src/type/i32_type.cc", + "src/type/i32_type.h", + "src/type/matrix_type.cc", + "src/type/matrix_type.h", + "src/type/multisampled_texture_type.cc", + "src/type/multisampled_texture_type.h", + "src/type/pointer_type.cc", + "src/type/pointer_type.h", + "src/type/sampled_texture_type.cc", + "src/type/sampled_texture_type.h", + "src/type/sampler_type.cc", + "src/type/sampler_type.h", + "src/type/storage_texture_type.cc", + "src/type/storage_texture_type.h", + "src/type/struct_type.cc", + "src/type/struct_type.h", + "src/type/texture_type.cc", + "src/type/texture_type.h", + "src/type/type.cc", + "src/type/type.h", + "src/type/type_manager.cc", + "src/type/type_manager.h", + "src/type/u32_type.cc", + "src/type/u32_type.h", + "src/type/vector_type.cc", + "src/type/vector_type.h", + "src/type/void_type.cc", + "src/type/void_type.h", "src/validator/validator_impl.cc", "src/validator/validator_impl.h", "src/validator/validator_test_helper.cc", @@ -804,25 +804,7 @@ source_set("tint_unittests_core_src") { "src/ast/switch_statement_test.cc", "src/ast/test_helper.h", "src/ast/traits_test.cc", - "src/ast/type/access_control_type_test.cc", - "src/ast/type/alias_type_test.cc", - "src/ast/type/array_type_test.cc", - "src/ast/type/bool_type_test.cc", - "src/ast/type/depth_texture_type_test.cc", - "src/ast/type/f32_type_test.cc", - "src/ast/type/i32_type_test.cc", - "src/ast/type/matrix_type_test.cc", - "src/ast/type/multisampled_texture_type_test.cc", - "src/ast/type/pointer_type_test.cc", - "src/ast/type/sampled_texture_type_test.cc", - "src/ast/type/sampler_type_test.cc", - "src/ast/type/storage_texture_type_test.cc", - "src/ast/type/struct_type_test.cc", - "src/ast/type/texture_type_test.cc", - "src/ast/type/u32_type_test.cc", - "src/ast/type/vector_type_test.cc", "src/ast/type_constructor_expression_test.cc", - "src/ast/type_manager_test.cc", "src/ast/uint_literal_test.cc", "src/ast/unary_op_expression_test.cc", "src/ast/variable_decl_statement_test.cc", @@ -844,6 +826,24 @@ source_set("tint_unittests_core_src") { "src/transform/test_helper.h", "src/transform/vertex_pulling_test.cc", "src/type_determiner_test.cc", + "src/type/access_control_type_test.cc", + "src/type/alias_type_test.cc", + "src/type/array_type_test.cc", + "src/type/bool_type_test.cc", + "src/type/depth_texture_type_test.cc", + "src/type/f32_type_test.cc", + "src/type/i32_type_test.cc", + "src/type/matrix_type_test.cc", + "src/type/multisampled_texture_type_test.cc", + "src/type/pointer_type_test.cc", + "src/type/sampled_texture_type_test.cc", + "src/type/sampler_type_test.cc", + "src/type/storage_texture_type_test.cc", + "src/type/struct_type_test.cc", + "src/type/texture_type_test.cc", + "src/type/type_manager_test.cc", + "src/type/u32_type_test.cc", + "src/type/vector_type_test.cc", "src/validator/validator_control_block_test.cc", "src/validator/validator_function_test.cc", "src/validator/validator_test.cc", diff --git a/fuzzers/tint_ast_clone_fuzzer.cc b/fuzzers/tint_ast_clone_fuzzer.cc index 6ce94bcde0..0ccf481694 100644 --- a/fuzzers/tint_ast_clone_fuzzer.cc +++ b/fuzzers/tint_ast_clone_fuzzer.cc @@ -67,7 +67,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { for (auto* src_node : src.nodes()) { src_nodes.emplace(src_node); } - std::unordered_set src_types; + std::unordered_set src_types; for (auto& src_type : src.types()) { src_types.emplace(src_type.second.get()); } diff --git a/include/tint/tint.h b/include/tint/tint.h index e9e7c9d7a4..19c69d1789 100644 --- a/include/tint/tint.h +++ b/include/tint/tint.h @@ -19,7 +19,6 @@ // headers will need to be moved to include/tint/. #include "src/ast/pipeline_stage.h" -#include "src/ast/type_manager.h" #include "src/demangler.h" #include "src/diagnostic/printer.h" #include "src/inspector/inspector.h" @@ -30,6 +29,7 @@ #include "src/transform/first_index_offset.h" #include "src/transform/manager.h" #include "src/transform/vertex_pulling.h" +#include "src/type/type_manager.h" #include "src/type_determiner.h" #include "src/validator/validator.h" #include "src/writer/writer.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c655d71de2..b7c4fa5c3d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,16 +56,16 @@ set(TINT_LIB_SRCS ast/bitcast_expression.h ast/block_statement.cc ast/block_statement.h - ast/bool_literal.h ast/bool_literal.cc + ast/bool_literal.h ast/break_statement.cc ast/break_statement.h ast/builder.cc ast/builder.h - ast/builtin.cc - ast/builtin.h ast/builtin_decoration.cc ast/builtin_decoration.h + ast/builtin.cc + ast/builtin.h ast/call_expression.cc ast/call_expression.h ast/call_statement.cc @@ -106,8 +106,8 @@ set(TINT_LIB_SRCS ast/int_literal.h ast/intrinsic.cc ast/intrinsic.h - ast/literal.h ast/literal.cc + ast/literal.h ast/location_decoration.cc ast/location_decoration.h ast/loop_statement.cc @@ -151,50 +151,10 @@ set(TINT_LIB_SRCS ast/switch_statement.cc ast/switch_statement.h ast/traits.h - ast/type_constructor_expression.h ast/type_constructor_expression.cc + ast/type_constructor_expression.h ast/type_decoration.cc ast/type_decoration.h - ast/type/access_control_type.cc - ast/type/access_control_type.h - ast/type/alias_type.cc - ast/type/alias_type.h - ast/type/array_type.cc - ast/type/array_type.h - ast/type/bool_type.cc - ast/type/bool_type.h - ast/type/depth_texture_type.cc - ast/type/depth_texture_type.h - ast/type/f32_type.cc - ast/type/f32_type.h - ast/type/i32_type.cc - ast/type/i32_type.h - ast/type/matrix_type.cc - ast/type/matrix_type.h - ast/type/multisampled_texture_type.cc - ast/type/multisampled_texture_type.h - ast/type/pointer_type.cc - ast/type/pointer_type.h - ast/type/sampled_texture_type.cc - ast/type/sampled_texture_type.h - ast/type/sampler_type.cc - ast/type/sampler_type.h - ast/type/storage_texture_type.cc - ast/type/storage_texture_type.h - ast/type/struct_type.cc - ast/type/struct_type.h - ast/type/texture_type.cc - ast/type/texture_type.h - ast/type/type.cc - ast/type/type.h - ast/type/u32_type.cc - ast/type/u32_type.h - ast/type/vector_type.cc - ast/type/vector_type.h - ast/type/void_type.cc - ast/type/void_type.h - ast/type_manager.cc - ast/type_manager.h ast/uint_literal.cc ast/uint_literal.h ast/unary_op.cc @@ -251,6 +211,46 @@ set(TINT_LIB_SRCS transform/vertex_pulling.h type_determiner.cc type_determiner.h + type/access_control_type.cc + type/access_control_type.h + type/alias_type.cc + type/alias_type.h + type/array_type.cc + type/array_type.h + type/bool_type.cc + type/bool_type.h + type/depth_texture_type.cc + type/depth_texture_type.h + type/f32_type.cc + type/f32_type.h + type/i32_type.cc + type/i32_type.h + type/matrix_type.cc + type/matrix_type.h + type/multisampled_texture_type.cc + type/multisampled_texture_type.h + type/pointer_type.cc + type/pointer_type.h + type/sampled_texture_type.cc + type/sampled_texture_type.h + type/sampler_type.cc + type/sampler_type.h + type/storage_texture_type.cc + type/storage_texture_type.h + type/struct_type.cc + type/struct_type.h + type/texture_type.cc + type/texture_type.h + type/type.cc + type/type.h + type/type_manager.cc + type/type_manager.h + type/u32_type.cc + type/u32_type.h + type/vector_type.cc + type/vector_type.h + type/void_type.cc + type/void_type.h validator/validator.cc validator/validator.h validator/validator_impl.cc @@ -391,6 +391,7 @@ if(${TINT_BUILD_TESTS}) ast/access_decoration_test.cc ast/array_accessor_expression_test.cc ast/assignment_statement_test.cc + ast/binary_expression_test.cc ast/binding_decoration_test.cc ast/bitcast_expression_test.cc ast/block_statement_test.cc @@ -403,8 +404,8 @@ if(${TINT_BUILD_TESTS}) ast/clone_context_test.cc ast/constant_id_decoration_test.cc ast/continue_statement_test.cc - ast/discard_statement_test.cc ast/decoration_test.cc + ast/discard_statement_test.cc ast/else_statement_test.cc ast/expression_test.cc ast/fallthrough_statement_test.cc @@ -413,53 +414,34 @@ if(${TINT_BUILD_TESTS}) ast/group_decoration_test.cc ast/identifier_expression_test.cc ast/if_statement_test.cc + ast/int_literal_test.cc ast/intrinsic_texture_helper_test.cc ast/intrinsic_texture_helper_test.h - ast/int_literal_test.cc ast/location_decoration_test.cc ast/loop_statement_test.cc ast/member_accessor_expression_test.cc - ast/module_test.cc ast/module_clone_test.cc + ast/module_test.cc ast/null_literal_test.cc - ast/binary_expression_test.cc ast/return_statement_test.cc ast/scalar_constructor_expression_test.cc ast/sint_literal_test.cc ast/stage_decoration_test.cc ast/stride_decoration_test.cc - ast/struct_member_test.cc ast/struct_member_offset_decoration_test.cc + ast/struct_member_test.cc ast/struct_test.cc ast/switch_statement_test.cc ast/test_helper.h - ast/type/access_control_type_test.cc - ast/type/alias_type_test.cc - ast/type/array_type_test.cc - ast/type/bool_type_test.cc - ast/type/depth_texture_type_test.cc - ast/type/f32_type_test.cc - ast/type/i32_type_test.cc - ast/type/matrix_type_test.cc - ast/type/multisampled_texture_type_test.cc - ast/type/pointer_type_test.cc - ast/type/sampled_texture_type_test.cc - ast/type/sampler_type_test.cc - ast/type/storage_texture_type_test.cc - ast/type/struct_type_test.cc - ast/type/texture_type_test.cc - ast/type/u32_type_test.cc - ast/type/vector_type_test.cc ast/traits_test.cc ast/type_constructor_expression_test.cc - ast/type_manager_test.cc ast/uint_literal_test.cc ast/unary_op_expression_test.cc ast/variable_decl_statement_test.cc ast/variable_test.cc ast/workgroup_decoration_test.cc - castable_test.cc block_allocator_test.cc + castable_test.cc demangler_test.cc diagnostic/formatter_test.cc diagnostic/printer_test.cc @@ -469,6 +451,24 @@ if(${TINT_BUILD_TESTS}) symbol_table_test.cc symbol_test.cc type_determiner_test.cc + type/access_control_type_test.cc + type/alias_type_test.cc + type/array_type_test.cc + type/bool_type_test.cc + type/depth_texture_type_test.cc + type/f32_type_test.cc + type/i32_type_test.cc + type/matrix_type_test.cc + type/multisampled_texture_type_test.cc + type/pointer_type_test.cc + type/sampled_texture_type_test.cc + type/sampler_type_test.cc + type/storage_texture_type_test.cc + type/struct_type_test.cc + type/texture_type_test.cc + type/type_manager_test.cc + type/u32_type_test.cc + type/vector_type_test.cc validator/validator_control_block_test.cc validator/validator_function_test.cc validator/validator_test.cc diff --git a/src/ast/bitcast_expression.h b/src/ast/bitcast_expression.h index ccee67edf2..d1376f2e76 100644 --- a/src/ast/bitcast_expression.h +++ b/src/ast/bitcast_expression.h @@ -20,7 +20,7 @@ #include "src/ast/expression.h" #include "src/ast/literal.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/bitcast_expression_test.cc b/src/ast/bitcast_expression_test.cc index dcbd7748b4..186e4b7c89 100644 --- a/src/ast/bitcast_expression_test.cc +++ b/src/ast/bitcast_expression_test.cc @@ -16,7 +16,7 @@ #include "src/ast/identifier_expression.h" #include "src/ast/test_helper.h" -#include "src/ast/type/f32_type.h" +#include "src/type/f32_type.h" namespace tint { namespace ast { diff --git a/src/ast/bool_literal_test.cc b/src/ast/bool_literal_test.cc index 97a9d5d10c..e07e66ea89 100644 --- a/src/ast/bool_literal_test.cc +++ b/src/ast/bool_literal_test.cc @@ -18,8 +18,8 @@ #include "src/ast/null_literal.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/bool_type.h" #include "src/ast/uint_literal.h" +#include "src/type/bool_type.h" namespace tint { namespace ast { diff --git a/src/ast/builder.h b/src/ast/builder.h index 1ebe604f25..35a49e1bcc 100644 --- a/src/ast/builder.h +++ b/src/ast/builder.h @@ -33,20 +33,20 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { namespace ast { diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index ce858dfc3b..ae60ba1dd1 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -18,9 +18,9 @@ #include "src/ast/if_statement.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" #include "src/ast/uint_literal.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" namespace tint { namespace ast { diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index 0d3403d575..0855fecdd9 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -19,7 +19,7 @@ #include "src/ast/if_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/test_helper.h" -#include "src/ast/type/bool_type.h" +#include "src/type/bool_type.h" namespace tint { namespace ast { diff --git a/src/ast/expression.h b/src/ast/expression.h index 12e038cfa5..853a57c523 100644 --- a/src/ast/expression.h +++ b/src/ast/expression.h @@ -20,7 +20,7 @@ #include #include "src/ast/node.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/expression_test.cc b/src/ast/expression_test.cc index b48409d6b5..c6887e308a 100644 --- a/src/ast/expression_test.cc +++ b/src/ast/expression_test.cc @@ -15,8 +15,8 @@ #include "src/ast/expression.h" #include "src/ast/test_helper.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/i32_type.h" +#include "src/type/alias_type.h" +#include "src/type/i32_type.h" namespace tint { namespace ast { diff --git a/src/ast/float_literal_test.cc b/src/ast/float_literal_test.cc index 1cd4cfe7a2..41be541a74 100644 --- a/src/ast/float_literal_test.cc +++ b/src/ast/float_literal_test.cc @@ -18,8 +18,8 @@ #include "src/ast/null_literal.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/f32_type.h" #include "src/ast/uint_literal.h" +#include "src/type/f32_type.h" namespace tint { namespace ast { diff --git a/src/ast/function.cc b/src/ast/function.cc index 822d8cbfa6..47863ca0aa 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -19,11 +19,11 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" #include "src/ast/stage_decoration.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/texture_type.h" #include "src/ast/variable.h" #include "src/ast/workgroup_decoration.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/texture_type.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::Function); diff --git a/src/ast/function.h b/src/ast/function.h index 19fb034e92..248dd55940 100644 --- a/src/ast/function.h +++ b/src/ast/function.h @@ -32,10 +32,10 @@ #include "src/ast/node.h" #include "src/ast/pipeline_stage.h" #include "src/ast/statement.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/type.h" #include "src/ast/variable.h" #include "src/symbol.h" +#include "src/type/sampler_type.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/int_literal_test.cc b/src/ast/int_literal_test.cc index dfeb534b7f..e207f8344a 100644 --- a/src/ast/int_literal_test.cc +++ b/src/ast/int_literal_test.cc @@ -19,9 +19,9 @@ #include "src/ast/null_literal.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" #include "src/ast/uint_literal.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" namespace tint { namespace ast { diff --git a/src/ast/intrinsic_texture_helper_test.cc b/src/ast/intrinsic_texture_helper_test.cc index 256de22bb5..b1a16c3505 100644 --- a/src/ast/intrinsic_texture_helper_test.cc +++ b/src/ast/intrinsic_texture_helper_test.cc @@ -15,12 +15,12 @@ #include "src/ast/intrinsic_texture_helper_test.h" #include "src/ast/builder.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/access_control_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" namespace tint { namespace ast { @@ -135,7 +135,7 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) { return out; } -ast::type::Type* TextureOverloadCase::resultVectorComponentType( +type::Type* TextureOverloadCase::resultVectorComponentType( ast::Builder* b) const { switch (texture_data_type) { case ast::intrinsic::test::TextureDataType::kF32: @@ -162,26 +162,26 @@ ast::Variable* TextureOverloadCase::buildTextureVariable( case ast::intrinsic::test::TextureKind::kRegular: return b->Var( "texture", ast::StorageClass::kUniformConstant, - b->create(texture_dimension, datatype), - nullptr, decos); + b->create(texture_dimension, datatype), nullptr, + decos); case ast::intrinsic::test::TextureKind::kDepth: return b->Var("texture", ast::StorageClass::kUniformConstant, - b->create(texture_dimension), - nullptr, decos); + b->create(texture_dimension), nullptr, + decos); case ast::intrinsic::test::TextureKind::kMultisampled: - return b->Var("texture", ast::StorageClass::kUniformConstant, - b->create(texture_dimension, - datatype), - nullptr, decos); + return b->Var( + "texture", ast::StorageClass::kUniformConstant, + b->create(texture_dimension, datatype), + nullptr, decos); case ast::intrinsic::test::TextureKind::kStorage: { auto* st = - b->create(texture_dimension, image_format); + b->create(texture_dimension, image_format); st->set_type(datatype); - auto* ac = b->create(access_control, st); + auto* ac = b->create(access_control, st); return b->Var("texture", ast::StorageClass::kUniformConstant, ac, nullptr, decos); } @@ -198,7 +198,7 @@ ast::Variable* TextureOverloadCase::buildSamplerVariable( b->create(1), }; return b->Var("sampler", ast::StorageClass::kUniformConstant, - b->create(sampler_kind), nullptr, decos); + b->create(sampler_kind), nullptr, decos); } std::vector TextureOverloadCase::ValidCases() { @@ -437,7 +437,7 @@ std::vector TextureOverloadCase::ValidCases() { ValidTextureOverload::kDimensionsStorageRO1d, "textureDimensions(t : texture_storage_1d) -> i32", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1d, TextureDataType::kF32, "textureDimensions", @@ -448,7 +448,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_1d_array) -> " "i32", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1dArray, TextureDataType::kF32, "textureDimensions", @@ -459,7 +459,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_2d) -> " "vec2", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", @@ -470,7 +470,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_2d_array) -> " "vec2", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", @@ -481,7 +481,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_3d) -> " "vec3", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k3d, TextureDataType::kF32, "textureDimensions", @@ -491,7 +491,7 @@ std::vector TextureOverloadCase::ValidCases() { ValidTextureOverload::kDimensionsStorageWO1d, "textureDimensions(t : texture_storage_1d) -> i32", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1d, TextureDataType::kF32, "textureDimensions", @@ -502,7 +502,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_1d_array) -> " "i32", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1dArray, TextureDataType::kF32, "textureDimensions", @@ -513,7 +513,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_2d) -> " "vec2", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", @@ -524,7 +524,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_2d_array) -> " "vec2", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", @@ -535,7 +535,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_3d) -> " "vec3", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k3d, TextureDataType::kF32, "textureDimensions", @@ -605,7 +605,7 @@ std::vector TextureOverloadCase::ValidCases() { ValidTextureOverload::kNumLayersStorageWO1dArray, "textureNumLayers(t : texture_storage_1d_array) -> i32", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1dArray, TextureDataType::kF32, "textureNumLayers", @@ -615,7 +615,7 @@ std::vector TextureOverloadCase::ValidCases() { ValidTextureOverload::kNumLayersStorageWO2dArray, "textureNumLayers(t : texture_storage_2d_array) -> i32", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2dArray, TextureDataType::kF32, "textureNumLayers", @@ -2240,7 +2240,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_1d,\n" " coords : i32) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1d, TextureDataType::kF32, "textureLoad", @@ -2256,7 +2256,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : i32,\n" " array_index : i32) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1dArray, TextureDataType::kF32, "textureLoad", @@ -2271,7 +2271,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba8Unorm, + type::ImageFormat::kRgba8Unorm, type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", @@ -2285,7 +2285,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba8Snorm, + type::ImageFormat::kRgba8Snorm, type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", @@ -2299,7 +2299,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba8Uint, + type::ImageFormat::kRgba8Uint, type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", @@ -2313,7 +2313,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba8Sint, + type::ImageFormat::kRgba8Sint, type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", @@ -2327,7 +2327,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba16Uint, + type::ImageFormat::kRgba16Uint, type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", @@ -2341,7 +2341,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba16Sint, + type::ImageFormat::kRgba16Sint, type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", @@ -2355,7 +2355,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba16Float, + type::ImageFormat::kRgba16Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", @@ -2369,7 +2369,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kR32Uint, + type::ImageFormat::kR32Uint, type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", @@ -2383,7 +2383,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kR32Sint, + type::ImageFormat::kR32Sint, type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", @@ -2397,7 +2397,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kR32Float, + type::ImageFormat::kR32Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", @@ -2411,7 +2411,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRg32Uint, + type::ImageFormat::kRg32Uint, type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", @@ -2425,7 +2425,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRg32Sint, + type::ImageFormat::kRg32Sint, type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", @@ -2439,7 +2439,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRg32Float, + type::ImageFormat::kRg32Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", @@ -2453,7 +2453,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Uint, + type::ImageFormat::kRgba32Uint, type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", @@ -2467,7 +2467,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Sint, + type::ImageFormat::kRgba32Sint, type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", @@ -2481,7 +2481,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_2d,\n" " coords : vec2) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", @@ -2497,7 +2497,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " array_index : i32) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2dArray, TextureDataType::kF32, "textureLoad", @@ -2512,7 +2512,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureLoad(t : texture_storage_3d,\n" " coords : vec3) -> vec4", ast::AccessControl::kReadOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k3d, TextureDataType::kF32, "textureLoad", @@ -2527,7 +2527,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : i32,\n" " value : vec4) -> void", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1d, TextureDataType::kF32, "textureStore", @@ -2544,7 +2544,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32,\n" " value : vec4) -> void", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k1dArray, TextureDataType::kF32, "textureStore", @@ -2561,7 +2561,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " value : vec4) -> void", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2d, TextureDataType::kF32, "textureStore", @@ -2578,7 +2578,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32,\n" " value : vec4) -> void", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k2dArray, TextureDataType::kF32, "textureStore", @@ -2595,7 +2595,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3,\n" " value : vec4) -> void", ast::AccessControl::kWriteOnly, - ast::type::ImageFormat::kRgba32Float, + type::ImageFormat::kRgba32Float, type::TextureDimension::k3d, TextureDataType::kF32, "textureStore", diff --git a/src/ast/intrinsic_texture_helper_test.h b/src/ast/intrinsic_texture_helper_test.h index bd67b9fab4..f8a4b53165 100644 --- a/src/ast/intrinsic_texture_helper_test.h +++ b/src/ast/intrinsic_texture_helper_test.h @@ -20,9 +20,9 @@ #include "src/ast/access_control.h" #include "src/ast/builder.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/texture_type.h" namespace tint { namespace ast { @@ -240,7 +240,7 @@ struct TextureOverloadCase { /// @param builder the AST builder used for the test /// @returns the vector component type of the texture function return value - ast::type::Type* resultVectorComponentType(ast::Builder* builder) const; + type::Type* resultVectorComponentType(ast::Builder* builder) const; /// @param builder the AST builder used for the test /// @returns a Variable holding the test texture ast::Variable* buildTextureVariable(ast::Builder* builder) const; diff --git a/src/ast/literal.h b/src/ast/literal.h index f5127ef11a..2b08eea39a 100644 --- a/src/ast/literal.h +++ b/src/ast/literal.h @@ -18,7 +18,7 @@ #include #include "src/ast/node.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/module.cc b/src/ast/module.cc index ac337d0860..3561263488 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -17,7 +17,7 @@ #include #include "src/ast/clone_context.h" -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" namespace tint { namespace ast { diff --git a/src/ast/module.h b/src/ast/module.h index 63fd9c75c9..76ed92e089 100644 --- a/src/ast/module.h +++ b/src/ast/module.h @@ -25,11 +25,11 @@ #include "src/ast/function.h" #include "src/ast/traits.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type_manager.h" #include "src/ast/variable.h" #include "src/block_allocator.h" #include "src/symbol_table.h" +#include "src/type/alias_type.h" +#include "src/type/type_manager.h" namespace tint { namespace ast { @@ -181,7 +181,7 @@ class Module { std::vector constructed_types_; FunctionList functions_; BlockAllocator ast_nodes_; - TypeManager type_mgr_; + type::Manager type_mgr_; }; } // namespace ast diff --git a/src/ast/module_clone_test.cc b/src/ast/module_clone_test.cc index 1c7fd7b831..e5007b0713 100644 --- a/src/ast/module_clone_test.cc +++ b/src/ast/module_clone_test.cc @@ -126,7 +126,7 @@ fn main() -> void { for (auto* src_node : src.nodes()) { src_nodes.emplace(src_node); } - std::unordered_set src_types; + std::unordered_set src_types; for (auto& src_type : src.types()) { src_types.emplace(src_type.second.get()); } diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index d195f325f9..605bdb801e 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -20,10 +20,10 @@ #include "gmock/gmock.h" #include "src/ast/function.h" #include "src/ast/test_helper.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/struct_type.h" #include "src/ast/variable.h" +#include "src/type/alias_type.h" +#include "src/type/f32_type.h" +#include "src/type/struct_type.h" namespace tint { namespace ast { diff --git a/src/ast/node.h b/src/ast/node.h index b3d5cdee28..87e2ee9fee 100644 --- a/src/ast/node.h +++ b/src/ast/node.h @@ -23,15 +23,14 @@ #include "src/source.h" namespace tint { +namespace type { +class Type; +} namespace ast { class Module; class CloneContext; -namespace type { -class Type; -} - /// AST base class node class Node : public Castable { public: diff --git a/src/ast/null_literal_test.cc b/src/ast/null_literal_test.cc index 025e02c303..93b6d44060 100644 --- a/src/ast/null_literal_test.cc +++ b/src/ast/null_literal_test.cc @@ -18,8 +18,8 @@ #include "src/ast/float_literal.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" #include "src/ast/uint_literal.h" +#include "src/type/i32_type.h" namespace tint { namespace ast { diff --git a/src/ast/scalar_constructor_expression_test.cc b/src/ast/scalar_constructor_expression_test.cc index 25fdbd2bfa..563a086d42 100644 --- a/src/ast/scalar_constructor_expression_test.cc +++ b/src/ast/scalar_constructor_expression_test.cc @@ -16,7 +16,7 @@ #include "src/ast/bool_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/bool_type.h" +#include "src/type/bool_type.h" namespace tint { namespace ast { diff --git a/src/ast/sint_literal_test.cc b/src/ast/sint_literal_test.cc index e4a32d21b7..3cdb7bbdaf 100644 --- a/src/ast/sint_literal_test.cc +++ b/src/ast/sint_literal_test.cc @@ -18,9 +18,9 @@ #include "src/ast/float_literal.h" #include "src/ast/null_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" #include "src/ast/uint_literal.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" namespace tint { namespace ast { diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 52204f80f1..9f06562c39 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -22,8 +22,8 @@ #include "src/ast/node.h" #include "src/ast/struct_member_decoration.h" -#include "src/ast/type/type.h" #include "src/symbol.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/struct_member_test.cc b/src/ast/struct_member_test.cc index df6758ace8..2591a640d4 100644 --- a/src/ast/struct_member_test.cc +++ b/src/ast/struct_member_test.cc @@ -19,7 +19,7 @@ #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" namespace tint { namespace ast { diff --git a/src/ast/struct_test.cc b/src/ast/struct_test.cc index a0af738b95..a34a2a6023 100644 --- a/src/ast/struct_test.cc +++ b/src/ast/struct_test.cc @@ -21,7 +21,7 @@ #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" namespace tint { namespace ast { diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index 175365812c..5f05e6af64 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -20,7 +20,7 @@ #include "src/ast/identifier_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" namespace tint { namespace ast { diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h index 66f45b1d29..1fdbeec1dc 100644 --- a/src/ast/type_constructor_expression.h +++ b/src/ast/type_constructor_expression.h @@ -19,7 +19,7 @@ #include #include "src/ast/constructor_expression.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc index 9b51d8e88b..b7bbfb0231 100644 --- a/src/ast/type_constructor_expression_test.cc +++ b/src/ast/type_constructor_expression_test.cc @@ -20,8 +20,8 @@ #include "src/ast/constructor_expression.h" #include "src/ast/identifier_expression.h" #include "src/ast/test_helper.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace ast { diff --git a/src/ast/uint_literal_test.cc b/src/ast/uint_literal_test.cc index 1197ba707d..db3e1bbefe 100644 --- a/src/ast/uint_literal_test.cc +++ b/src/ast/uint_literal_test.cc @@ -19,7 +19,7 @@ #include "src/ast/null_literal.h" #include "src/ast/sint_literal.h" #include "src/ast/test_helper.h" -#include "src/ast/type/u32_type.h" +#include "src/type/u32_type.h" namespace tint { namespace ast { diff --git a/src/ast/variable.h b/src/ast/variable.h index 88257b23f1..e721ad0afb 100644 --- a/src/ast/variable.h +++ b/src/ast/variable.h @@ -23,9 +23,9 @@ #include "src/ast/expression.h" #include "src/ast/node.h" #include "src/ast/storage_class.h" -#include "src/ast/type/type.h" #include "src/ast/variable_decoration.h" #include "src/symbol.h" +#include "src/type/type.h" namespace tint { namespace ast { diff --git a/src/ast/variable_decl_statement_test.cc b/src/ast/variable_decl_statement_test.cc index a432804b5b..60b878b28e 100644 --- a/src/ast/variable_decl_statement_test.cc +++ b/src/ast/variable_decl_statement_test.cc @@ -15,8 +15,8 @@ #include "src/ast/variable_decl_statement.h" #include "src/ast/test_helper.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" +#include "src/type/f32_type.h" namespace tint { namespace ast { diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc index 7f19618664..331d17ffbb 100644 --- a/src/ast/variable_test.cc +++ b/src/ast/variable_test.cc @@ -17,8 +17,8 @@ #include "src/ast/constant_id_decoration.h" #include "src/ast/identifier_expression.h" #include "src/ast/test_helper.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" namespace tint { namespace ast { diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index f23e95420f..91d6cd1881 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -25,20 +25,20 @@ #include "src/ast/null_literal.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace inspector { @@ -183,12 +183,12 @@ std::vector Inspector::GetUniformBufferResourceBindings( ast::Variable* var = nullptr; ast::Function::BindingInfo binding_info; std::tie(var, binding_info) = ruv; - if (!var->type()->Is()) { + if (!var->type()->Is()) { continue; } auto* unwrapped_type = var->type()->UnwrapIfNeeded(); - auto* str = unwrapped_type->As(); + auto* str = unwrapped_type->As(); if (str == nullptr) { continue; } @@ -199,8 +199,8 @@ std::vector Inspector::GetUniformBufferResourceBindings( entry.bind_group = binding_info.group->value(); entry.binding = binding_info.binding->value(); - entry.min_buffer_binding_size = var->type()->MinBufferBindingSize( - ast::type::MemoryLayout::kUniformBuffer); + entry.min_buffer_binding_size = + var->type()->MinBufferBindingSize(type::MemoryLayout::kUniformBuffer); result.push_back(entry); } @@ -307,7 +307,7 @@ std::vector Inspector::GetStorageBufferResourceBindingsImpl( ast::Function::BindingInfo binding_info; std::tie(var, binding_info) = rsv; - auto* ac_type = var->type()->As(); + auto* ac_type = var->type()->As(); if (ac_type == nullptr) { continue; } @@ -316,14 +316,14 @@ std::vector Inspector::GetStorageBufferResourceBindingsImpl( continue; } - if (!var->type()->UnwrapIfNeeded()->Is()) { + if (!var->type()->UnwrapIfNeeded()->Is()) { continue; } entry.bind_group = binding_info.group->value(); entry.binding = binding_info.binding->value(); - entry.min_buffer_binding_size = var->type()->MinBufferBindingSize( - ast::type::MemoryLayout::kStorageBuffer); + entry.min_buffer_binding_size = + var->type()->MinBufferBindingSize(type::MemoryLayout::kStorageBuffer); result.push_back(entry); } @@ -352,28 +352,27 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( entry.bind_group = binding_info.group->value(); entry.binding = binding_info.binding->value(); - auto* texture_type = - var->type()->UnwrapIfNeeded()->As(); + auto* texture_type = var->type()->UnwrapIfNeeded()->As(); switch (texture_type->dim()) { - case ast::type::TextureDimension::k1d: + case type::TextureDimension::k1d: entry.dim = ResourceBinding::TextureDimension::k1d; break; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: entry.dim = ResourceBinding::TextureDimension::k1dArray; break; - case ast::type::TextureDimension::k2d: + case type::TextureDimension::k2d: entry.dim = ResourceBinding::TextureDimension::k2d; break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: entry.dim = ResourceBinding::TextureDimension::k2dArray; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: entry.dim = ResourceBinding::TextureDimension::k3d; break; - case ast::type::TextureDimension::kCube: + case type::TextureDimension::kCube: entry.dim = ResourceBinding::TextureDimension::kCube; break; - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: entry.dim = ResourceBinding::TextureDimension::kCubeArray; break; default: @@ -381,30 +380,29 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( break; } - ast::type::Type* base_type = nullptr; + type::Type* base_type = nullptr; if (multisampled_only) { - base_type = texture_type->As() + base_type = texture_type->As() ->type() ->UnwrapIfNeeded(); } else { - base_type = texture_type->As() - ->type() - ->UnwrapIfNeeded(); + base_type = + texture_type->As()->type()->UnwrapIfNeeded(); } - if (auto* at = base_type->As()) { + if (auto* at = base_type->As()) { base_type = at->type(); - } else if (auto* mt = base_type->As()) { + } else if (auto* mt = base_type->As()) { base_type = mt->type(); - } else if (auto* vt = base_type->As()) { + } else if (auto* vt = base_type->As()) { base_type = vt->type(); } - if (base_type->Is()) { + if (base_type->Is()) { entry.sampled_kind = ResourceBinding::SampledKind::kFloat; - } else if (base_type->Is()) { + } else if (base_type->Is()) { entry.sampled_kind = ResourceBinding::SampledKind::kUInt; - } else if (base_type->Is()) { + } else if (base_type->Is()) { entry.sampled_kind = ResourceBinding::SampledKind::kSInt; } else { entry.sampled_kind = ResourceBinding::SampledKind::kUnknown; diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 6f6f76cdbf..ae64c86839 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -39,27 +39,27 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decoration.h" #include "src/ast/workgroup_decoration.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/struct_type.h" +#include "src/type/type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "tint/tint.h" @@ -72,8 +72,8 @@ class InspectorHelper : public ast::BuilderWithModule { InspectorHelper() : td_(std::make_unique(mod)), inspector_(std::make_unique(*mod)), - sampler_type_(ast::type::SamplerKind::kSampler), - comparison_sampler_type_(ast::type::SamplerKind::kComparisonSampler) {} + sampler_type_(type::SamplerKind::kSampler), + comparison_sampler_type_(type::SamplerKind::kComparisonSampler) {} /// Generates an empty function /// @param name name of the function created @@ -177,10 +177,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param val value to initialize the variable with, if NULL no initializer /// will be added. template - void AddConstantID(std::string name, - uint32_t id, - ast::type::Type* type, - T* val) { + void AddConstantID(std::string name, uint32_t id, type::Type* type, T* val) { ast::Expression* constructor = nullptr; if (val) { constructor = @@ -196,28 +193,28 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param type AST type of the literal, must resolve to BoolLiteral /// @param val scalar value for the literal to contain /// @returns a Literal of the expected type and value - ast::Literal* MakeLiteral(ast::type::Type* type, bool* val) { + ast::Literal* MakeLiteral(type::Type* type, bool* val) { return create(type, *val); } /// @param type AST type of the literal, must resolve to UIntLiteral /// @param val scalar value for the literal to contain /// @returns a Literal of the expected type and value - ast::Literal* MakeLiteral(ast::type::Type* type, uint32_t* val) { + ast::Literal* MakeLiteral(type::Type* type, uint32_t* val) { return create(type, *val); } /// @param type AST type of the literal, must resolve to IntLiteral /// @param val scalar value for the literal to contain /// @returns a Literal of the expected type and value - ast::Literal* MakeLiteral(ast::type::Type* type, int32_t* val) { + ast::Literal* MakeLiteral(type::Type* type, int32_t* val) { return create(type, *val); } /// @param type AST type of the literal, must resolve to FloattLiteral /// @param val scalar value for the literal to contain /// @returns a Literal of the expected type and value - ast::Literal* MakeLiteral(ast::type::Type* type, float* val) { + ast::Literal* MakeLiteral(type::Type* type, float* val) { return create(type, *val); } @@ -238,7 +235,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param idx index of member /// @param type type of member /// @returns a string for the member - std::string StructMemberName(size_t idx, ast::type::Type* type) { + std::string StructMemberName(size_t idx, type::Type* type) { return std::to_string(idx) + type->type_name(); } @@ -248,13 +245,13 @@ class InspectorHelper : public ast::BuilderWithModule { /// type and offset of a member of the struct /// @param is_block whether or not to decorate as a Block /// @returns a struct type - ast::type::Struct* MakeStructType( + type::Struct* MakeStructType( const std::string& name, - std::vector> members_info, + std::vector> members_info, bool is_block) { ast::StructMemberList members; for (auto& member_info : members_info) { - ast::type::Type* type; + type::Type* type; uint32_t offset; std::tie(type, offset) = member_info; @@ -278,12 +275,12 @@ class InspectorHelper : public ast::BuilderWithModule { /// @returns a tuple {struct type, access control type}, where the struct has /// the layout for an uniform buffer, and the control type wraps the /// struct. - std::tuple> + std::tuple> MakeUniformBufferTypes( const std::string& name, - std::vector> members_info) { + std::vector> members_info) { auto* struct_type = MakeStructType(name, members_info, true); - auto access_type = std::make_unique( + auto access_type = std::make_unique( ast::AccessControl::kReadOnly, struct_type); return {struct_type, std::move(access_type)}; } @@ -295,12 +292,12 @@ class InspectorHelper : public ast::BuilderWithModule { /// @returns a tuple {struct type, access control type}, where the struct has /// the layout for a storage buffer, and the control type wraps the /// struct. - std::tuple> + std::tuple> MakeStorageBufferTypes( const std::string& name, - std::vector> members_info) { + std::vector> members_info) { auto* struct_type = MakeStructType(name, members_info, false); - auto access_type = std::make_unique( + auto access_type = std::make_unique( ast::AccessControl::kReadWrite, struct_type); return {struct_type, std::move(access_type)}; } @@ -312,12 +309,12 @@ class InspectorHelper : public ast::BuilderWithModule { /// @returns a tuple {struct type, access control type}, where the struct has /// the layout for a read-only storage buffer, and the control type /// wraps the struct. - std::tuple> + std::tuple> MakeReadOnlyStorageBufferTypes( const std::string& name, - std::vector> members_info) { + std::vector> members_info) { auto* struct_type = MakeStructType(name, members_info, false); - auto access_type = std::make_unique( + auto access_type = std::make_unique( ast::AccessControl::kReadOnly, struct_type); return {struct_type, std::move(access_type)}; } @@ -329,7 +326,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param group the binding and group to use for the uniform buffer /// @param binding the binding number to use for the uniform buffer void AddBinding(const std::string& name, - ast::type::Type* type, + type::Type* type, ast::StorageClass storage_class, uint32_t group, uint32_t binding) { @@ -348,7 +345,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param group the binding/group/ to use for the uniform buffer /// @param binding the binding number to use for the uniform buffer void AddUniformBuffer(const std::string& name, - ast::type::Type* type, + type::Type* type, uint32_t group, uint32_t binding) { AddBinding(name, type, ast::StorageClass::kUniform, group, binding); @@ -360,7 +357,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param group the binding/group to use for the storage buffer /// @param binding the binding number to use for the storage buffer void AddStorageBuffer(const std::string& name, - ast::type::Type* type, + type::Type* type, uint32_t group, uint32_t binding) { AddBinding(name, type, ast::StorageClass::kStorage, group, binding); @@ -374,11 +371,11 @@ class InspectorHelper : public ast::BuilderWithModule { ast::Function* MakeStructVariableReferenceBodyFunction( std::string func_name, std::string struct_name, - std::vector> members) { + std::vector> members) { ast::StatementList stmts; for (auto member : members) { size_t member_idx; - ast::type::Type* member_type; + type::Type* member_type; std::tie(member_idx, member_type) = member; std::string member_name = StructMemberName(member_idx, member_type); @@ -388,7 +385,7 @@ class InspectorHelper : public ast::BuilderWithModule { for (auto member : members) { size_t member_idx; - ast::type::Type* member_type; + type::Type* member_type; std::tie(member_idx, member_type) = member; std::string member_name = StructMemberName(member_idx, member_type); @@ -427,28 +424,28 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param dim the dimensions of the texture /// @param type the data type of the sampled texture /// @returns the generated SampleTextureType - std::unique_ptr MakeSampledTextureType( - ast::type::TextureDimension dim, - ast::type::Type* type) { - return std::make_unique(dim, type); + std::unique_ptr MakeSampledTextureType( + type::TextureDimension dim, + type::Type* type) { + return std::make_unique(dim, type); } /// Generates a DepthTexture appropriate for the params /// @param dim the dimensions of the texture /// @returns the generated DepthTexture - std::unique_ptr MakeDepthTextureType( - ast::type::TextureDimension dim) { - return std::make_unique(dim); + std::unique_ptr MakeDepthTextureType( + type::TextureDimension dim) { + return std::make_unique(dim); } /// Generates a MultisampledTexture appropriate for the params /// @param dim the dimensions of the texture /// @param type the data type of the sampled texture /// @returns the generated SampleTextureType - std::unique_ptr MakeMultisampledTextureType( - ast::type::TextureDimension dim, - ast::type::Type* type) { - return std::make_unique(dim, type); + std::unique_ptr MakeMultisampledTextureType( + type::TextureDimension dim, + type::Type* type) { + return std::make_unique(dim, type); } /// Adds a sampled texture variable to the module @@ -457,7 +454,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param group the binding/group to use for the sampled texture /// @param binding the binding number to use for the sampled texture void AddSampledTexture(const std::string& name, - ast::type::Type* type, + type::Type* type, uint32_t group, uint32_t binding) { AddBinding(name, type, ast::StorageClass::kUniformConstant, group, binding); @@ -469,13 +466,13 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param group the binding/group to use for the multi-sampled texture /// @param binding the binding number to use for the multi-sampled texture void AddMultisampledTexture(const std::string& name, - ast::type::Type* type, + type::Type* type, uint32_t group, uint32_t binding) { AddBinding(name, type, ast::StorageClass::kUniformConstant, group, binding); } - void AddGlobalVariable(const std::string& name, ast::type::Type* type) { + void AddGlobalVariable(const std::string& name, type::Type* type) { mod->AddGlobalVariable( Var(name, ast::StorageClass::kUniformConstant, type)); } @@ -483,7 +480,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// Adds a depth texture variable to the module /// @param name the name of the variable /// @param type the type to use - void AddDepthTexture(const std::string& name, ast::type::Type* type) { + void AddDepthTexture(const std::string& name, type::Type* type) { mod->AddGlobalVariable( Var(name, ast::StorageClass::kUniformConstant, type)); } @@ -501,7 +498,7 @@ class InspectorHelper : public ast::BuilderWithModule { const std::string& texture_name, const std::string& sampler_name, const std::string& coords_name, - ast::type::Type* base_type, + type::Type* base_type, ast::FunctionDecorationList decorations) { std::string result_name = "sampler_result"; @@ -533,7 +530,7 @@ class InspectorHelper : public ast::BuilderWithModule { const std::string& sampler_name, const std::string& coords_name, const std::string& array_index, - ast::type::Type* base_type, + type::Type* base_type, ast::FunctionDecorationList decorations) { std::string result_name = "sampler_result"; @@ -567,7 +564,7 @@ class InspectorHelper : public ast::BuilderWithModule { const std::string& sampler_name, const std::string& coords_name, const std::string& depth_name, - ast::type::Type* base_type, + type::Type* base_type, ast::FunctionDecorationList decorations) { std::string result_name = "sampler_result"; @@ -586,7 +583,7 @@ class InspectorHelper : public ast::BuilderWithModule { /// Gets an appropriate type for the data in a given texture type. /// @param sampled_kind type of in the texture /// @returns a pointer to a type appropriate for the coord param - ast::type::Type* GetBaseType(ResourceBinding::SampledKind sampled_kind) { + type::Type* GetBaseType(ResourceBinding::SampledKind sampled_kind) { switch (sampled_kind) { case ResourceBinding::SampledKind::kFloat: return ty.f32; @@ -604,15 +601,15 @@ class InspectorHelper : public ast::BuilderWithModule { /// @param dim dimensionality of the texture being sampled /// @param sampled_kind type of data in the texture /// @returns a pointer to a type appropriate for the coord param - ast::type::Type* GetCoordsType(ast::type::TextureDimension dim, - ResourceBinding::SampledKind sampled_kind) { - ast::type::Type* base_type = GetBaseType(sampled_kind); - if (dim == ast::type::TextureDimension::k1d) { + type::Type* GetCoordsType(type::TextureDimension dim, + ResourceBinding::SampledKind sampled_kind) { + type::Type* base_type = GetBaseType(sampled_kind); + if (dim == type::TextureDimension::k1d) { return base_type; - } else if (dim == ast::type::TextureDimension::k1dArray || - dim == ast::type::TextureDimension::k2d) { + } else if (dim == type::TextureDimension::k1dArray || + dim == type::TextureDimension::k2d) { return vec_type(base_type, 2); - } else if (dim == ast::type::TextureDimension::kCubeArray) { + } else if (dim == type::TextureDimension::kCubeArray) { return vec_type(base_type, 4); } return vec_type(base_type, 3); @@ -621,38 +618,35 @@ class InspectorHelper : public ast::BuilderWithModule { TypeDeterminer* td() { return td_.get(); } Inspector* inspector() { return inspector_.get(); } - ast::type::Array* u32_array_type(uint32_t count) { + type::Array* u32_array_type(uint32_t count) { if (array_type_memo_.find(count) == array_type_memo_.end()) { array_type_memo_[count] = - create(ty.u32, count, - ast::ArrayDecorationList{ - create(4), - }); + create(ty.u32, count, + ast::ArrayDecorationList{ + create(4), + }); } return array_type_memo_[count]; } - ast::type::Vector* vec_type(ast::type::Type* type, uint32_t count) { + type::Vector* vec_type(type::Type* type, uint32_t count) { if (vector_type_memo_.find(std::tie(type, count)) == vector_type_memo_.end()) { vector_type_memo_[std::tie(type, count)] = - std::make_unique(ty.u32, count); + std::make_unique(ty.u32, count); } return vector_type_memo_[std::tie(type, count)].get(); } - ast::type::Sampler* sampler_type() { return &sampler_type_; } - ast::type::Sampler* comparison_sampler_type() { - return &comparison_sampler_type_; - } + type::Sampler* sampler_type() { return &sampler_type_; } + type::Sampler* comparison_sampler_type() { return &comparison_sampler_type_; } private: std::unique_ptr td_; std::unique_ptr inspector_; - ast::type::Sampler sampler_type_; - ast::type::Sampler comparison_sampler_type_; - std::map array_type_memo_; - std::map, - std::unique_ptr> + type::Sampler sampler_type_; + type::Sampler comparison_sampler_type_; + std::map array_type_memo_; + std::map, std::unique_ptr> vector_type_memo_; }; @@ -680,7 +674,7 @@ class InspectorGetSampledArrayTextureResourceBindingsTest : public InspectorHelper, public testing::Test {}; struct GetSampledTextureTestParams { - ast::type::TextureDimension type_dim; + type::TextureDimension type_dim; inspector::ResourceBinding::TextureDimension inspector_dim; inspector::ResourceBinding::SampledKind sampled_kind; }; @@ -1287,8 +1281,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingEntryPoint) { } TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes("foo_type", {{ty.i32, 0}}); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); @@ -1340,8 +1334,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) { } TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes("foo_type", {{ty.i32, 0}}); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); @@ -1369,8 +1363,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) { } TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes( "foo_type", {{ty.i32, 0}, {ty.u32, 4}, {ty.f32, 8}}); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); @@ -1398,8 +1392,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) { } TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { - ast::type::Struct* ub_struct_type; - std::unique_ptr ub_control_type; + type::Struct* ub_struct_type; + std::unique_ptr ub_control_type; std::tie(ub_struct_type, ub_control_type) = MakeUniformBufferTypes( "ub_type", {{ty.i32, 0}, {ty.u32, 4}, {ty.f32, 8}}); AddUniformBuffer("ub_foo", ub_control_type.get(), 0, 0); @@ -1450,8 +1444,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { } TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes("foo_type", {{ty.i32, 0}, {u32_array_type(4), 4}}); AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0); @@ -1479,8 +1473,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) { } TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes("foo_type", {{ty.i32, 0}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1508,8 +1502,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) { } TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes( "foo_type", {{ty.i32, 0}, {ty.u32, 4}, {ty.f32, 8}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1537,8 +1531,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) { } TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { - ast::type::Struct* sb_struct_type; - std::unique_ptr sb_control_type; + type::Struct* sb_struct_type; + std::unique_ptr sb_control_type; std::tie(sb_struct_type, sb_control_type) = MakeStorageBufferTypes( "sb_type", {{ty.i32, 0}, {ty.u32, 4}, {ty.f32, 8}}); AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0); @@ -1592,8 +1586,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { } TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes("foo_type", {{ty.i32, 0}, {u32_array_type(4), 4}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1621,8 +1615,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) { } TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes("foo_type", {{ty.i32, 0}, {u32_array_type(0), 4}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1650,8 +1644,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) { } TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes("foo_type", {{ty.i32, 0}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1675,8 +1669,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) { } TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes("foo_type", {{ty.i32, 0}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1706,8 +1700,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) { TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, MultipleStorageBuffers) { - ast::type::Struct* sb_struct_type; - std::unique_ptr sb_control_type; + type::Struct* sb_struct_type; + std::unique_ptr sb_control_type; std::tie(sb_struct_type, sb_control_type) = MakeReadOnlyStorageBufferTypes( "sb_type", {{ty.i32, 0}, {ty.u32, 4}, {ty.f32, 8}}); AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0); @@ -1762,8 +1756,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, } TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes( "foo_type", {{ty.i32, 0}, {u32_array_type(4), 4}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1793,8 +1787,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) { TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingRuntimeArray) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes( "foo_type", {{ty.i32, 0}, {u32_array_type(0), 4}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1823,8 +1817,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, } TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { - ast::type::Struct* foo_struct_type; - std::unique_ptr foo_control_type; + type::Struct* foo_struct_type; + std::unique_ptr foo_control_type; std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes("foo_type", {{ty.i32, 0}}); AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0); @@ -1850,7 +1844,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) { auto sampled_texture_type = - MakeSampledTextureType(ast::type::TextureDimension::k1d, ty.f32); + MakeSampledTextureType(type::TextureDimension::k1d, ty.f32); AddSampledTexture("foo_texture", sampled_texture_type.get(), 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -1889,7 +1883,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) { TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { auto sampled_texture_type = - MakeSampledTextureType(ast::type::TextureDimension::k1d, ty.f32); + MakeSampledTextureType(type::TextureDimension::k1d, ty.f32); AddSampledTexture("foo_texture", sampled_texture_type.get(), 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -1917,7 +1911,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { auto sampled_texture_type = - MakeSampledTextureType(ast::type::TextureDimension::k1d, ty.f32); + MakeSampledTextureType(type::TextureDimension::k1d, ty.f32); AddSampledTexture("foo_texture", sampled_texture_type.get(), 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -1936,8 +1930,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { - auto depth_texture_type = - MakeDepthTextureType(ast::type::TextureDimension::k2d); + auto depth_texture_type = MakeDepthTextureType(type::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type.get()); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -1959,8 +1952,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) { - auto depth_texture_type = - MakeDepthTextureType(ast::type::TextureDimension::k2d); + auto depth_texture_type = MakeDepthTextureType(type::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type.get()); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -1999,8 +1991,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { - auto depth_texture_type = - MakeDepthTextureType(ast::type::TextureDimension::k2d); + auto depth_texture_type = MakeDepthTextureType(type::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type.get()); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -2029,8 +2020,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { - auto depth_texture_type = - MakeDepthTextureType(ast::type::TextureDimension::k2d); + auto depth_texture_type = MakeDepthTextureType(type::TextureDimension::k2d); AddDepthTexture("foo_texture", depth_texture_type.get()); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -2051,7 +2041,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) { auto sampled_texture_type = - MakeSampledTextureType(ast::type::TextureDimension::k1d, ty.f32); + MakeSampledTextureType(type::TextureDimension::k1d, ty.f32); AddSampledTexture("foo_texture", sampled_texture_type.get(), 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32); @@ -2125,51 +2115,51 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetSampledTextureResourceBindingsTestWithParam, testing::Values( GetSampledTextureTestParams{ - ast::type::TextureDimension::k1d, + type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k1d, + type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k1d, + type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kUInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kUInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k3d, + type::TextureDimension::k3d, inspector::ResourceBinding::TextureDimension::k3d, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k3d, + type::TextureDimension::k3d, inspector::ResourceBinding::TextureDimension::k3d, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k3d, + type::TextureDimension::k3d, inspector::ResourceBinding::TextureDimension::k3d, inspector::ResourceBinding::SampledKind::kUInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::kCube, + type::TextureDimension::kCube, inspector::ResourceBinding::TextureDimension::kCube, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::kCube, + type::TextureDimension::kCube, inspector::ResourceBinding::TextureDimension::kCube, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::kCube, + type::TextureDimension::kCube, inspector::ResourceBinding::TextureDimension::kCube, inspector::ResourceBinding::SampledKind::kUInt})); @@ -2209,39 +2199,39 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetSampledArrayTextureResourceBindingsTestWithParam, testing::Values( GetSampledTextureTestParams{ - ast::type::TextureDimension::k1dArray, + type::TextureDimension::k1dArray, inspector::ResourceBinding::TextureDimension::k1dArray, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k1dArray, + type::TextureDimension::k1dArray, inspector::ResourceBinding::TextureDimension::k1dArray, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k1dArray, + type::TextureDimension::k1dArray, inspector::ResourceBinding::TextureDimension::k1dArray, inspector::ResourceBinding::SampledKind::kUInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kUInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, inspector::ResourceBinding::TextureDimension::kCubeArray, inspector::ResourceBinding::SampledKind::kFloat}, GetSampledTextureTestParams{ - ast::type::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, inspector::ResourceBinding::TextureDimension::kCubeArray, inspector::ResourceBinding::SampledKind::kSInt}, GetSampledTextureTestParams{ - ast::type::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, inspector::ResourceBinding::TextureDimension::kCubeArray, inspector::ResourceBinding::SampledKind::kUInt})); @@ -2287,27 +2277,27 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetMultisampledTextureResourceBindingsTestWithParam, testing::Values( GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k1d, + type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kFloat}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k1d, + type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kSInt}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k1d, + type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kUInt}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kFloat}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kSInt}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kUInt})); @@ -2360,27 +2350,27 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam, testing::Values( GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k1dArray, + type::TextureDimension::k1dArray, inspector::ResourceBinding::TextureDimension::k1dArray, inspector::ResourceBinding::SampledKind::kFloat}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k1dArray, + type::TextureDimension::k1dArray, inspector::ResourceBinding::TextureDimension::k1dArray, inspector::ResourceBinding::SampledKind::kSInt}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k1dArray, + type::TextureDimension::k1dArray, inspector::ResourceBinding::TextureDimension::k1dArray, inspector::ResourceBinding::SampledKind::kUInt}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kFloat}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kSInt}, GetMultisampledTextureTestParams{ - ast::type::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kUInt})); diff --git a/src/reader/spirv/enum_converter.cc b/src/reader/spirv/enum_converter.cc index 8719140860..f53c4a6344 100644 --- a/src/reader/spirv/enum_converter.cc +++ b/src/reader/spirv/enum_converter.cc @@ -94,85 +94,85 @@ ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b) { return ast::Builtin::kNone; } -ast::type::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) { +type::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) { if (arrayed) { switch (dim) { case SpvDim1D: - return ast::type::TextureDimension::k1dArray; + return type::TextureDimension::k1dArray; case SpvDim2D: - return ast::type::TextureDimension::k2dArray; + return type::TextureDimension::k2dArray; case SpvDimCube: - return ast::type::TextureDimension::kCubeArray; + return type::TextureDimension::kCubeArray; default: break; } Fail() << "arrayed dimension must be 1D, 2D, or Cube. Got " << int(dim); - return ast::type::TextureDimension::kNone; + return type::TextureDimension::kNone; } // Assume non-arrayed switch (dim) { case SpvDim1D: - return ast::type::TextureDimension::k1d; + return type::TextureDimension::k1d; case SpvDim2D: - return ast::type::TextureDimension::k2d; + return type::TextureDimension::k2d; case SpvDim3D: - return ast::type::TextureDimension::k3d; + return type::TextureDimension::k3d; case SpvDimCube: - return ast::type::TextureDimension::kCube; + return type::TextureDimension::kCube; default: break; } Fail() << "invalid dimension: " << int(dim); - return ast::type::TextureDimension::kNone; + return type::TextureDimension::kNone; } -ast::type::ImageFormat EnumConverter::ToImageFormat(SpvImageFormat fmt) { +type::ImageFormat EnumConverter::ToImageFormat(SpvImageFormat fmt) { switch (fmt) { case SpvImageFormatUnknown: - return ast::type::ImageFormat::kNone; + return type::ImageFormat::kNone; // 8 bit channels case SpvImageFormatRgba8: - return ast::type::ImageFormat::kRgba8Unorm; + return type::ImageFormat::kRgba8Unorm; case SpvImageFormatRgba8Snorm: - return ast::type::ImageFormat::kRgba8Snorm; + return type::ImageFormat::kRgba8Snorm; case SpvImageFormatRgba8ui: - return ast::type::ImageFormat::kRgba8Uint; + return type::ImageFormat::kRgba8Uint; case SpvImageFormatRgba8i: - return ast::type::ImageFormat::kRgba8Sint; + return type::ImageFormat::kRgba8Sint; // 16 bit channels case SpvImageFormatRgba16ui: - return ast::type::ImageFormat::kRgba16Uint; + return type::ImageFormat::kRgba16Uint; case SpvImageFormatRgba16i: - return ast::type::ImageFormat::kRgba16Sint; + return type::ImageFormat::kRgba16Sint; case SpvImageFormatRgba16f: - return ast::type::ImageFormat::kRgba16Float; + return type::ImageFormat::kRgba16Float; // 32 bit channels case SpvImageFormatR32ui: - return ast::type::ImageFormat::kR32Uint; + return type::ImageFormat::kR32Uint; case SpvImageFormatR32i: - return ast::type::ImageFormat::kR32Sint; + return type::ImageFormat::kR32Sint; case SpvImageFormatR32f: - return ast::type::ImageFormat::kR32Float; + return type::ImageFormat::kR32Float; case SpvImageFormatRg32ui: - return ast::type::ImageFormat::kRg32Uint; + return type::ImageFormat::kRg32Uint; case SpvImageFormatRg32i: - return ast::type::ImageFormat::kRg32Sint; + return type::ImageFormat::kRg32Sint; case SpvImageFormatRg32f: - return ast::type::ImageFormat::kRg32Float; + return type::ImageFormat::kRg32Float; case SpvImageFormatRgba32ui: - return ast::type::ImageFormat::kRgba32Uint; + return type::ImageFormat::kRgba32Uint; case SpvImageFormatRgba32i: - return ast::type::ImageFormat::kRgba32Sint; + return type::ImageFormat::kRgba32Sint; case SpvImageFormatRgba32f: - return ast::type::ImageFormat::kRgba32Float; + return type::ImageFormat::kRgba32Float; default: break; } Fail() << "invalid image format: " << int(fmt); - return ast::type::ImageFormat::kNone; + return type::ImageFormat::kNone; } } // namespace spirv diff --git a/src/reader/spirv/enum_converter.h b/src/reader/spirv/enum_converter.h index fdcef1f526..59c7d042d8 100644 --- a/src/reader/spirv/enum_converter.h +++ b/src/reader/spirv/enum_converter.h @@ -19,8 +19,8 @@ #include "src/ast/builtin.h" #include "src/ast/pipeline_stage.h" #include "src/ast/storage_class.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/texture_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/texture_type.h" #include "src/reader/spirv/fail_stream.h" namespace tint { @@ -59,13 +59,13 @@ class EnumConverter { /// @param dim the SPIR-V Dim value /// @param arrayed true if the texture is arrayed /// @returns a Tint AST texture dimension - ast::type::TextureDimension ToDim(SpvDim dim, bool arrayed); + type::TextureDimension ToDim(SpvDim dim, bool arrayed); /// Converts a SPIR-V Image Format to a Tint ImageFormat /// On failure, logs an error and returns kNone /// @param fmt the SPIR-V format /// @returns a Tint AST format - ast::type::ImageFormat ToImageFormat(SpvImageFormat fmt); + type::ImageFormat ToImageFormat(SpvImageFormat fmt); private: /// Registers a failure and returns a stream for log diagnostics. diff --git a/src/reader/spirv/enum_converter_test.cc b/src/reader/spirv/enum_converter_test.cc index bf4c5c0f66..ad8adc1fbc 100644 --- a/src/reader/spirv/enum_converter_test.cc +++ b/src/reader/spirv/enum_converter_test.cc @@ -236,7 +236,7 @@ struct DimCase { SpvDim dim; bool arrayed; bool expect_success; - ast::type::TextureDimension expected; + type::TextureDimension expected; }; inline std::ostream& operator<<(std::ostream& out, DimCase dc) { out << "DimCase{ SpvDim:" << int(dc.dim) << " arrayed?:" << int(dc.arrayed) @@ -280,41 +280,39 @@ INSTANTIATE_TEST_SUITE_P( SpvDimTest, testing::Values( // Non-arrayed - DimCase{SpvDim1D, false, true, ast::type::TextureDimension::k1d}, - DimCase{SpvDim2D, false, true, ast::type::TextureDimension::k2d}, - DimCase{SpvDim3D, false, true, ast::type::TextureDimension::k3d}, - DimCase{SpvDimCube, false, true, ast::type::TextureDimension::kCube}, + DimCase{SpvDim1D, false, true, type::TextureDimension::k1d}, + DimCase{SpvDim2D, false, true, type::TextureDimension::k2d}, + DimCase{SpvDim3D, false, true, type::TextureDimension::k3d}, + DimCase{SpvDimCube, false, true, type::TextureDimension::kCube}, // Arrayed - DimCase{SpvDim1D, true, true, ast::type::TextureDimension::k1dArray}, - DimCase{SpvDim2D, true, true, ast::type::TextureDimension::k2dArray}, - DimCase{SpvDimCube, true, true, - ast::type::TextureDimension::kCubeArray})); + DimCase{SpvDim1D, true, true, type::TextureDimension::k1dArray}, + DimCase{SpvDim2D, true, true, type::TextureDimension::k2dArray}, + DimCase{SpvDimCube, true, true, type::TextureDimension::kCubeArray})); INSTANTIATE_TEST_SUITE_P( EnumConverterBad, SpvDimTest, testing::Values( // Invalid SPIR-V dimensionality. - DimCase{SpvDimMax, false, false, ast::type::TextureDimension::kNone}, - DimCase{SpvDimMax, true, false, ast::type::TextureDimension::kNone}, + DimCase{SpvDimMax, false, false, type::TextureDimension::kNone}, + DimCase{SpvDimMax, true, false, type::TextureDimension::kNone}, // Vulkan non-arrayed dimensionalities not supported by WGSL. - DimCase{SpvDimRect, false, false, ast::type::TextureDimension::kNone}, - DimCase{SpvDimBuffer, false, false, ast::type::TextureDimension::kNone}, - DimCase{SpvDimSubpassData, false, false, - ast::type::TextureDimension::kNone}, + DimCase{SpvDimRect, false, false, type::TextureDimension::kNone}, + DimCase{SpvDimBuffer, false, false, type::TextureDimension::kNone}, + DimCase{SpvDimSubpassData, false, false, type::TextureDimension::kNone}, // Arrayed dimensionalities not supported by WGSL - DimCase{SpvDim3D, true, false, ast::type::TextureDimension::kNone}, - DimCase{SpvDimRect, true, false, ast::type::TextureDimension::kNone}, - DimCase{SpvDimBuffer, true, false, ast::type::TextureDimension::kNone}, + DimCase{SpvDim3D, true, false, type::TextureDimension::kNone}, + DimCase{SpvDimRect, true, false, type::TextureDimension::kNone}, + DimCase{SpvDimBuffer, true, false, type::TextureDimension::kNone}, DimCase{SpvDimSubpassData, true, false, - ast::type::TextureDimension::kNone})); + type::TextureDimension::kNone})); // ImageFormat struct ImageFormatCase { SpvImageFormat format; bool expect_success; - ast::type::ImageFormat expected; + type::ImageFormat expected; }; inline std::ostream& operator<<(std::ostream& out, ImageFormatCase ifc) { out << "ImageFormatCase{ SpvImageFormat:" << int(ifc.format) @@ -358,85 +356,70 @@ INSTANTIATE_TEST_SUITE_P( SpvImageFormatTest, testing::Values( // Unknown. This is used for sampled images. - ImageFormatCase{SpvImageFormatUnknown, true, - ast::type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatUnknown, true, type::ImageFormat::kNone}, // 8 bit channels ImageFormatCase{SpvImageFormatRgba8, true, - ast::type::ImageFormat::kRgba8Unorm}, + type::ImageFormat::kRgba8Unorm}, ImageFormatCase{SpvImageFormatRgba8Snorm, true, - ast::type::ImageFormat::kRgba8Snorm}, + type::ImageFormat::kRgba8Snorm}, ImageFormatCase{SpvImageFormatRgba8ui, true, - ast::type::ImageFormat::kRgba8Uint}, + type::ImageFormat::kRgba8Uint}, ImageFormatCase{SpvImageFormatRgba8i, true, - ast::type::ImageFormat::kRgba8Sint}, + type::ImageFormat::kRgba8Sint}, // 16 bit channels ImageFormatCase{SpvImageFormatRgba16ui, true, - ast::type::ImageFormat::kRgba16Uint}, + type::ImageFormat::kRgba16Uint}, ImageFormatCase{SpvImageFormatRgba16i, true, - ast::type::ImageFormat::kRgba16Sint}, + type::ImageFormat::kRgba16Sint}, ImageFormatCase{SpvImageFormatRgba16f, true, - ast::type::ImageFormat::kRgba16Float}, + type::ImageFormat::kRgba16Float}, // 32 bit channels // ... 1 channel - ImageFormatCase{SpvImageFormatR32ui, true, - ast::type::ImageFormat::kR32Uint}, - ImageFormatCase{SpvImageFormatR32i, true, - ast::type::ImageFormat::kR32Sint}, - ImageFormatCase{SpvImageFormatR32f, true, - ast::type::ImageFormat::kR32Float}, + ImageFormatCase{SpvImageFormatR32ui, true, type::ImageFormat::kR32Uint}, + ImageFormatCase{SpvImageFormatR32i, true, type::ImageFormat::kR32Sint}, + ImageFormatCase{SpvImageFormatR32f, true, type::ImageFormat::kR32Float}, // ... 2 channels ImageFormatCase{SpvImageFormatRg32ui, true, - ast::type::ImageFormat::kRg32Uint}, + type::ImageFormat::kRg32Uint}, ImageFormatCase{SpvImageFormatRg32i, true, - ast::type::ImageFormat::kRg32Sint}, + type::ImageFormat::kRg32Sint}, ImageFormatCase{SpvImageFormatRg32f, true, - ast::type::ImageFormat::kRg32Float}, + type::ImageFormat::kRg32Float}, // ... 4 channels ImageFormatCase{SpvImageFormatRgba32ui, true, - ast::type::ImageFormat::kRgba32Uint}, + type::ImageFormat::kRgba32Uint}, ImageFormatCase{SpvImageFormatRgba32i, true, - ast::type::ImageFormat::kRgba32Sint}, + type::ImageFormat::kRgba32Sint}, ImageFormatCase{SpvImageFormatRgba32f, true, - ast::type::ImageFormat::kRgba32Float})); + type::ImageFormat::kRgba32Float})); -INSTANTIATE_TEST_SUITE_P(EnumConverterBad, - SpvImageFormatTest, - testing::Values( - // Scanning in order from the SPIR-V spec. - ImageFormatCase{SpvImageFormatRg16f, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatR11fG11fB10f, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatR16f, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRgb10A2, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg16, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg8, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatR16, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatR8, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRgba16Snorm, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg16Snorm, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg8Snorm, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg16i, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg8i, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatR8i, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRgb10a2ui, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg16ui, false, - ast::type::ImageFormat::kNone}, - ImageFormatCase{SpvImageFormatRg8ui, false, - ast::type::ImageFormat::kNone})); +INSTANTIATE_TEST_SUITE_P( + EnumConverterBad, + SpvImageFormatTest, + testing::Values( + // Scanning in order from the SPIR-V spec. + ImageFormatCase{SpvImageFormatRg16f, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatR11fG11fB10f, false, + type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatR16f, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRgb10A2, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg16, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg8, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatR16, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatR8, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRgba16Snorm, false, + type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg16Snorm, false, + type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg8Snorm, false, + type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg16i, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg8i, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatR8i, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRgb10a2ui, false, + type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg16ui, false, type::ImageFormat::kNone}, + ImageFormatCase{SpvImageFormatRg8ui, false, type::ImageFormat::kNone})); } // namespace } // namespace spirv diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index af6e3b5bb2..a18127f800 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -53,18 +53,6 @@ #include "src/ast/stage_decoration.h" #include "src/ast/storage_class.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op.h" @@ -74,6 +62,18 @@ #include "src/reader/spirv/construct.h" #include "src/reader/spirv/fail_stream.h" #include "src/reader/spirv/parser_impl.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/texture_type.h" +#include "src/type/type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" // Terms: // CFG: the control flow graph of the function, where basic blocks are the @@ -725,7 +725,7 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi, fail_stream_(pi->fail_stream()), namer_(pi->namer()), function_(function), - i32_(ast_module_.create()), + i32_(ast_module_.create()), ep_info_(ep_info) { PushNewStatementBlock(nullptr, 0, nullptr); } @@ -929,7 +929,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) { return success(); } -ast::type::Type* FunctionEmitter::GetVariableStoreType( +type::Type* FunctionEmitter::GetVariableStoreType( const spvtools::opt::Instruction& var_decl_inst) { const auto type_id = var_decl_inst.type_id(); auto* var_ref_type = type_mgr_->GetType(type_id); @@ -1998,7 +1998,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) { << id; return {}; case SkipReason::kPointSizeBuiltinValue: { - auto* f32 = create(); + auto* f32 = create(); return {f32, create( Source{}, create(Source{}, f32, 1.0f))}; @@ -2985,8 +2985,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) { } auto expr = MakeExpression(ptr_id); // The load result type is the pointee type of its operand. - assert(expr.type->Is()); - expr.type = expr.type->As()->type(); + assert(expr.type->Is()); + expr.type = expr.type->As()->type(); return EmitConstDefOrWriteToHoistedVar(inst, expr); } @@ -3043,7 +3043,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue( const auto opcode = inst.opcode(); - ast::type::Type* ast_type = + type::Type* ast_type = inst.type_id() != 0 ? parser_impl_.ConvertType(inst.type_id()) : nullptr; auto binary_op = ConvertBinaryOp(opcode); @@ -3181,7 +3181,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst( auto* func = create( Source{}, ast_module_.RegisterSymbol(name)); ast::ExpressionList operands; - ast::type::Type* first_operand_type = nullptr; + type::Type* first_operand_type = nullptr; // All parameters to GLSL.std.450 extended instructions are IDs. for (uint32_t iarg = 2; iarg < inst.NumInOperands(); ++iarg) { TypedExpression operand = MakeOperand(inst, iarg); @@ -3423,7 +3423,7 @@ TypedExpression FunctionEmitter::MakeAccessChain( type_mgr_->FindPointerToType(pointee_type_id, storage_class); auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id); assert(ast_pointer_type); - assert(ast_pointer_type->Is()); + assert(ast_pointer_type->Is()); current_expr = TypedExpression{ast_pointer_type, next_expr}; } return current_expr; @@ -3443,7 +3443,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract( TypedExpression current_expr(MakeOperand(inst, 0)); auto make_index = [this, source](uint32_t literal) { - auto* type = create(); + auto* type = create(); return create( source, create(source, type, literal)); }; @@ -3551,7 +3551,7 @@ ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const { } ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const { - ast::type::Bool bool_type; + type::Bool bool_type; return create( source, create(source, parser_impl_.Bool(), false)); } @@ -3572,8 +3572,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle( // Generate an ast::TypeConstructor expression. // Assume the literal indices are valid, and there is a valid number of them. auto source = GetSourceForInst(inst); - ast::type::Vector* result_type = - parser_impl_.ConvertType(inst.type_id())->As(); + type::Vector* result_type = + parser_impl_.ConvertType(inst.type_id())->As(); ast::ExpressionList values; for (uint32_t i = 2; i < inst.NumInOperands(); ++i) { const auto index = inst.GetSingleWordInOperand(i); @@ -3642,7 +3642,7 @@ bool FunctionEmitter::RegisterLocallyDefinedValues() { if (type) { if (type->AsPointer()) { if (const auto* ast_type = parser_impl_.ConvertType(inst.type_id())) { - if (auto* ptr = ast_type->As()) { + if (auto* ptr = ast_type->As()) { info->storage_class = ptr->storage_class(); } } @@ -3686,21 +3686,21 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) { const auto type_id = def_use_mgr_->GetDef(id)->type_id(); if (type_id) { auto* ast_type = parser_impl_.ConvertType(type_id); - if (ast_type && ast_type->Is()) { - return ast_type->As()->storage_class(); + if (ast_type && ast_type->Is()) { + return ast_type->As()->storage_class(); } } return ast::StorageClass::kNone; } -ast::type::Type* FunctionEmitter::RemapStorageClass(ast::type::Type* type, - uint32_t result_id) { - if (const auto* ast_ptr_type = type->As()) { +type::Type* FunctionEmitter::RemapStorageClass(type::Type* type, + uint32_t result_id) { + if (const auto* ast_ptr_type = type->As()) { // Remap an old-style storage buffer pointer to a new-style storage // buffer pointer. const auto sc = GetStorageClassForPointerValue(result_id); if (ast_ptr_type->storage_class() != sc) { - return parser_impl_.get_module().create( + return parser_impl_.get_module().create( ast_ptr_type->type(), sc); } } @@ -3884,7 +3884,7 @@ TypedExpression FunctionEmitter::MakeNumericConversion( return {}; } - ast::type::Type* expr_type = nullptr; + type::Type* expr_type = nullptr; if ((opcode == SpvOpConvertSToF) || (opcode == SpvOpConvertUToF)) { if (arg_expr.type->is_integer_scalar_or_vector()) { expr_type = requested_type; @@ -3946,7 +3946,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) { << inst.PrettyPrint(); } - if (result_type->Is()) { + if (result_type->Is()) { return nullptr != AddStatement(create(Source{}, call_expr)); } @@ -3965,7 +3965,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall( ident->set_intrinsic(intrinsic); ast::ExpressionList params; - ast::type::Type* first_operand_type = nullptr; + type::Type* first_operand_type = nullptr; for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) { TypedExpression operand = MakeOperand(inst, iarg); if (first_operand_type == nullptr) { @@ -3997,8 +3997,8 @@ TypedExpression FunctionEmitter::MakeSimpleSelect( // - you can't select over pointers or pointer vectors, unless you also have // a VariablePointers* capability, which is not allowed in by WebGPU. auto* op_ty = operand1.type; - if (op_ty->Is() || op_ty->is_float_scalar() || - op_ty->is_integer_scalar() || op_ty->Is()) { + if (op_ty->Is() || op_ty->is_float_scalar() || + op_ty->is_integer_scalar() || op_ty->Is()) { ast::ExpressionList params; params.push_back(operand1.expr); params.push_back(operand2.expr); @@ -4050,13 +4050,12 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { Source{}, ast_module_.RegisterSymbol(param_name))); } - ast::type::Pointer* texture_ptr_type = - parser_impl_.GetTypeForHandleVar(*image); + type::Pointer* texture_ptr_type = parser_impl_.GetTypeForHandleVar(*image); if (!texture_ptr_type) { return Fail(); } - ast::type::Texture* texture_type = - texture_ptr_type->type()->UnwrapAll()->As(); + type::Texture* texture_type = + texture_ptr_type->type()->UnwrapAll()->As(); if (!texture_type) { return Fail(); } @@ -4160,7 +4159,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { } TypedExpression lod = MakeOperand(inst, arg_index); // When sampling from a depth texture, the Lod operand must be an I32. - if (texture_type->Is()) { + if (texture_type->Is()) { // Convert it to a signed integer type. lod = ToI32(lod); } @@ -4188,9 +4187,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { << inst.PrettyPrint(); } switch (texture_type->dim()) { - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::k2dArray: - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + case type::TextureDimension::k3d: break; default: return Fail() << "ConstOffset is only permitted for 2D, 2D Arrayed, " @@ -4226,7 +4225,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { // The result type, derived from the SPIR-V instruction. auto* result_type = parser_impl_.ConvertType(inst.type_id()); auto* result_component_type = result_type; - if (auto* result_vector_type = result_type->As()) { + if (auto* result_vector_type = result_type->As()) { result_component_type = result_vector_type->type(); } @@ -4241,7 +4240,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { // dref gather vec4 ImageFetch vec4 TODO(dneto) // Construct a 4-element vector with the result from the builtin in the // first component. - if (texture_type->Is()) { + if (texture_type->Is()) { if (is_non_dref_sample || (opcode == SpvOpImageFetch)) { value = create( Source{}, @@ -4269,7 +4268,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { // or vice versa. Perform a bitcast. value = create(Source{}, result_type, call_expr); } - if (!expected_component_type->Is() && + if (!expected_component_type->Is() && IsSampledImageAccess(opcode)) { // WGSL permits sampled image access only on float textures. // Reject this case in the SPIR-V reader, at least until SPIR-V validation @@ -4326,22 +4325,21 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess( if (!raw_coords.type) { return {}; } - ast::type::Pointer* type = parser_impl_.GetTypeForHandleVar(*image); + type::Pointer* type = parser_impl_.GetTypeForHandleVar(*image); if (!parser_impl_.success()) { Fail(); return {}; } - if (!type || !type->type()->UnwrapAll()->Is()) { + if (!type || !type->type()->UnwrapAll()->Is()) { Fail() << "invalid texture type for " << image->PrettyPrint(); return {}; } auto* unwrapped_type = type->type()->UnwrapAll(); - ast::type::TextureDimension dim = - unwrapped_type->As()->dim(); + type::TextureDimension dim = unwrapped_type->As()->dim(); // Number of regular coordinates. - uint32_t num_axes = ast::type::NumCoordinateAxes(dim); - bool is_arrayed = ast::type::IsTextureArray(dim); + uint32_t num_axes = type::NumCoordinateAxes(dim); + bool is_arrayed = type::IsTextureArray(dim); if ((num_axes == 0) || (num_axes > 3)) { Fail() << "unsupported image dimensionality for " << type->type_name() << " prompted by " << inst.PrettyPrint(); @@ -4352,7 +4350,7 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess( if (component_type->is_float_scalar() || component_type->is_integer_scalar()) { num_coords_supplied = 1; - } else if (auto* vec_type = raw_coords.type->As()) { + } else if (auto* vec_type = raw_coords.type->As()) { component_type = vec_type->type(); num_coords_supplied = vec_type->size(); } @@ -4377,9 +4375,9 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess( // will actually use them. auto prefix_swizzle_expr = [this, num_axes, component_type, raw_coords]() -> ast::Expression* { - auto* swizzle_type = - (num_axes == 1) ? component_type - : create(component_type, num_axes); + auto* swizzle_type = (num_axes == 1) + ? component_type + : create(component_type, num_axes); auto* swizzle = create( Source{}, raw_coords.expr, PrefixSwizzle(num_axes)); return ToSignedIfUnsigned({swizzle_type, swizzle}).expr; @@ -4413,8 +4411,8 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess( ast::Expression* FunctionEmitter::ConvertTexelForStorage( const spvtools::opt::Instruction& inst, TypedExpression texel, - ast::type::Texture* texture_type) { - auto* storage_texture_type = texture_type->As(); + type::Texture* texture_type) { + auto* storage_texture_type = texture_type->As(); auto* src_type = texel.type; if (!storage_texture_type) { Fail() << "writing to other than storage texture: " << inst.PrettyPrint(); @@ -4431,14 +4429,14 @@ ast::Expression* FunctionEmitter::ConvertTexelForStorage( } const uint32_t dest_count = - dest_type->is_scalar() ? 1 : dest_type->As()->size(); + dest_type->is_scalar() ? 1 : dest_type->As()->size(); if (dest_count == 3) { Fail() << "3-channel storage textures are not supported: " << inst.PrettyPrint(); return nullptr; } const uint32_t src_count = - src_type->is_scalar() ? 1 : src_type->As()->size(); + src_type->is_scalar() ? 1 : src_type->As()->size(); if (src_count < dest_count) { Fail() << "texel has too few components for storage texture: " << src_count << " provided but " << dest_count @@ -4508,8 +4506,8 @@ TypedExpression FunctionEmitter::ToSignedIfUnsigned(TypedExpression value) { if (!value.type || !value.type->is_unsigned_scalar_or_vector()) { return value; } - if (auto* vec_type = value.type->As()) { - auto* new_type = create(i32_, vec_type->size()); + if (auto* vec_type = value.type->As()) { + auto* new_type = create(i32_, vec_type->size()); return {new_type, create( Source{}, new_type, ast::ExpressionList{value.expr})}; } @@ -4560,10 +4558,10 @@ TypedExpression FunctionEmitter::MakeOuterProduct( // Synthesize the result. auto col = MakeOperand(inst, 0); auto row = MakeOperand(inst, 1); - auto* col_ty = col.type->As(); - auto* row_ty = row.type->As(); + auto* col_ty = col.type->As(); + auto* row_ty = row.type->As(); auto* result_ty = - parser_impl_.ConvertType(inst.type_id())->As(); + parser_impl_.ConvertType(inst.type_id())->As(); if (!col_ty || !col_ty || !result_ty || result_ty->type() != col_ty->type() || result_ty->type() != row_ty->type() || result_ty->columns() != row_ty->size() || diff --git a/src/reader/spirv/function.h b/src/reader/spirv/function.h index 74dc3cae33..6ea6e367d3 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h @@ -36,12 +36,12 @@ #include "src/ast/module.h" #include "src/ast/statement.h" #include "src/ast/storage_class.h" -#include "src/ast/type/i32_type.h" #include "src/reader/spirv/construct.h" #include "src/reader/spirv/entry_point_info.h" #include "src/reader/spirv/fail_stream.h" #include "src/reader/spirv/namer.h" #include "src/reader/spirv/parser_impl.h" +#include "src/type/i32_type.h" namespace tint { namespace reader { @@ -485,7 +485,7 @@ class FunctionEmitter { /// @param type the AST type /// @param result_id the SPIR-V ID for the locally defined value /// @returns an possibly updated type - ast::type::Type* RemapStorageClass(ast::type::Type* type, uint32_t result_id); + type::Type* RemapStorageClass(type::Type* type, uint32_t result_id); /// Marks locally defined values when they should get a 'const' /// definition in WGSL, or a 'var' definition at an outer scope. @@ -804,7 +804,7 @@ class FunctionEmitter { /// Function parameters ast::VariableList params; /// Function return type - ast::type::Type* return_type; + type::Type* return_type; /// Function decorations ast::FunctionDecorationList decorations; }; @@ -817,7 +817,7 @@ class FunctionEmitter { /// @returns the store type for the OpVariable instruction, or /// null on failure. - ast::type::Type* GetVariableStoreType( + type::Type* GetVariableStoreType( const spvtools::opt::Instruction& var_decl_inst); /// Returns an expression for an instruction operand. Signedness conversion is @@ -874,7 +874,7 @@ class FunctionEmitter { ast::Expression* ConvertTexelForStorage( const spvtools::opt::Instruction& inst, TypedExpression texel, - ast::type::Texture* texture_type); + type::Texture* texture_type); /// Returns an expression for an OpSelect, if its operands are scalars /// or vectors. These translate directly to WGSL select. Otherwise, return @@ -1037,7 +1037,7 @@ class FunctionEmitter { FailStream& fail_stream_; Namer& namer_; const spvtools::opt::Function& function_; - ast::type::I32* const i32_; // The unique I32 type object. + type::I32* const i32_; // The unique I32 type object. // A stack of statement lists. Each list is contained in a construct in // the next deeper element of stack. The 0th entry represents the statements diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index a9b7281e70..5a3a1d9820 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -52,24 +52,6 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" @@ -79,6 +61,24 @@ #include "src/reader/spirv/enum_converter.h" #include "src/reader/spirv/function.h" #include "src/reader/spirv/usage.h" +#include "src/type/access_control_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { namespace reader { @@ -255,7 +255,7 @@ ParserImpl::ParserImpl(const std::vector& spv_binary) : Reader(), spv_binary_(spv_binary), fail_stream_(&success_, &errors_), - bool_type_(ast_module_.create()), + bool_type_(ast_module_.create()), namer_(fail_stream_), enum_converter_(fail_stream_), tools_context_(kInputEnv) { @@ -313,7 +313,7 @@ ast::Module ParserImpl::module() { return std::move(ast_module_); } -ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) { +type::Type* ParserImpl::ConvertType(uint32_t type_id) { if (!success_) { return nullptr; } @@ -334,7 +334,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) { return nullptr; } - auto save = [this, type_id, spirv_type](ast::type::Type* type) { + auto save = [this, type_id, spirv_type](type::Type* type) { if (type != nullptr) { id_to_type_[type_id] = type; MaybeGenerateAlias(type_id, spirv_type); @@ -344,7 +344,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) { switch (spirv_type->kind()) { case spvtools::opt::analysis::Type::kVoid: - return save(ast_module_.create()); + return save(ast_module_.create()); case spvtools::opt::analysis::Type::kBool: return save(bool_type_); case spvtools::opt::analysis::Type::kInteger: @@ -374,7 +374,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) { case spvtools::opt::analysis::Type::kImage: // Fake it for sampler and texture types. These are handled in an // entirely different way. - return save(ast_module_.create()); + return save(ast_module_.create()); default: break; } @@ -710,11 +710,11 @@ bool ParserImpl::RegisterEntryPoints() { return success_; } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Integer* int_ty) { if (int_ty->width() == 32) { - ast::type::Type* signed_ty = ast_module_.create(); - ast::type::Type* unsigned_ty = ast_module_.create(); + type::Type* signed_ty = ast_module_.create(); + type::Type* unsigned_ty = ast_module_.create(); signed_type_for_[unsigned_ty] = signed_ty; unsigned_type_for_[signed_ty] = unsigned_ty; return int_ty->IsSigned() ? signed_ty : unsigned_ty; @@ -723,31 +723,31 @@ ast::type::Type* ParserImpl::ConvertType( return nullptr; } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Float* float_ty) { if (float_ty->width() == 32) { - return ast_module_.create(); + return ast_module_.create(); } Fail() << "unhandled float width: " << float_ty->width(); return nullptr; } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Vector* vec_ty) { const auto num_elem = vec_ty->element_count(); auto* ast_elem_ty = ConvertType(type_mgr_->GetId(vec_ty->element_type())); if (ast_elem_ty == nullptr) { return nullptr; } - auto* this_ty = ast_module_.create(ast_elem_ty, num_elem); + auto* this_ty = ast_module_.create(ast_elem_ty, num_elem); // Generate the opposite-signedness vector type, if this type is integral. if (unsigned_type_for_.count(ast_elem_ty)) { - auto* other_ty = ast_module_.create( + auto* other_ty = ast_module_.create( unsigned_type_for_[ast_elem_ty], num_elem); signed_type_for_[other_ty] = this_ty; unsigned_type_for_[this_ty] = other_ty; } else if (signed_type_for_.count(ast_elem_ty)) { - auto* other_ty = ast_module_.create( + auto* other_ty = ast_module_.create( signed_type_for_[ast_elem_ty], num_elem); unsigned_type_for_[other_ty] = this_ty; signed_type_for_[this_ty] = other_ty; @@ -755,7 +755,7 @@ ast::type::Type* ParserImpl::ConvertType( return this_ty; } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Matrix* mat_ty) { const auto* vec_ty = mat_ty->element_type()->AsVector(); const auto* scalar_ty = vec_ty->element_type(); @@ -765,11 +765,10 @@ ast::type::Type* ParserImpl::ConvertType( if (ast_scalar_ty == nullptr) { return nullptr; } - return ast_module_.create(ast_scalar_ty, num_rows, - num_columns); + return ast_module_.create(ast_scalar_ty, num_rows, num_columns); } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::RuntimeArray* rtarr_ty) { auto* ast_elem_ty = ConvertType(type_mgr_->GetId(rtarr_ty->element_type())); if (ast_elem_ty == nullptr) { @@ -779,10 +778,10 @@ ast::type::Type* ParserImpl::ConvertType( if (!ParseArrayDecorations(rtarr_ty, &decorations)) { return nullptr; } - return create(ast_elem_ty, 0, std::move(decorations)); + return create(ast_elem_ty, 0, std::move(decorations)); } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Array* arr_ty) { const auto elem_type_id = type_mgr_->GetId(arr_ty->element_type()); auto* ast_elem_ty = ConvertType(elem_type_id); @@ -824,8 +823,8 @@ ast::type::Type* ParserImpl::ConvertType( if (remap_buffer_block_type_.count(elem_type_id)) { remap_buffer_block_type_.insert(type_mgr_->GetId(arr_ty)); } - return create(ast_elem_ty, static_cast(num_elem), - std::move(decorations)); + return create(ast_elem_ty, static_cast(num_elem), + std::move(decorations)); } bool ParserImpl::ParseArrayDecorations( @@ -857,7 +856,7 @@ bool ParserImpl::ParseArrayDecorations( return true; } -ast::type::Type* ParserImpl::ConvertType( +type::Type* ParserImpl::ConvertType( uint32_t type_id, const spvtools::opt::analysis::Struct* struct_ty) { // Compute the struct decoration. @@ -964,7 +963,7 @@ ast::type::Type* ParserImpl::ConvertType( namer_.SuggestSanitizedName(type_id, "S"); auto name = namer_.GetName(type_id); - auto* result = ast_module_.create( + auto* result = ast_module_.create( ast_module_.RegisterSymbol(name), ast_struct); id_to_type_[type_id] = result; if (num_non_writable_members == members.size()) { @@ -974,9 +973,8 @@ ast::type::Type* ParserImpl::ConvertType( return result; } -ast::type::Type* ParserImpl::ConvertType( - uint32_t type_id, - const spvtools::opt::analysis::Pointer*) { +type::Type* ParserImpl::ConvertType(uint32_t type_id, + const spvtools::opt::analysis::Pointer*) { const auto* inst = def_use_mgr_->GetDef(type_id); const auto pointee_type_id = inst->GetSingleWordInOperand(1); const auto storage_class = SpvStorageClass(inst->GetSingleWordInOperand(0)); @@ -1005,7 +1003,7 @@ ast::type::Type* ParserImpl::ConvertType( ast_storage_class = ast::StorageClass::kStorage; remap_buffer_block_type_.insert(type_id); } - return ast_module_.create(ast_elem_ty, ast_storage_class); + return ast_module_.create(ast_elem_ty, ast_storage_class); } bool ParserImpl::RegisterTypes() { @@ -1038,7 +1036,7 @@ bool ParserImpl::EmitScalarSpecConstants() { // that is OpSpecConstantTrue, OpSpecConstantFalse, or OpSpecConstant. for (auto& inst : module_->types_values()) { // These will be populated for a valid scalar spec constant. - ast::type::Type* ast_type = nullptr; + type::Type* ast_type = nullptr; ast::ScalarConstructorExpression* ast_expr = nullptr; switch (inst.opcode()) { @@ -1054,17 +1052,17 @@ bool ParserImpl::EmitScalarSpecConstants() { case SpvOpSpecConstant: { ast_type = ConvertType(inst.type_id()); const uint32_t literal_value = inst.GetSingleWordInOperand(0); - if (ast_type->Is()) { + if (ast_type->Is()) { ast_expr = create( Source{}, create(Source{}, ast_type, static_cast(literal_value))); - } else if (ast_type->Is()) { + } else if (ast_type->Is()) { ast_expr = create( Source{}, create(Source{}, ast_type, static_cast(literal_value))); - } else if (ast_type->Is()) { + } else if (ast_type->Is()) { float float_value; // Copy the bits so we can read them as a float. std::memcpy(&float_value, &literal_value, sizeof(float_value)); @@ -1131,7 +1129,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id, return; } const auto name = namer_.GetName(type_id); - auto* ast_alias_type = ast_module_.create( + auto* ast_alias_type = ast_module_.create( ast_module_.RegisterSymbol(name), ast_underlying_type); // Record this new alias as the AST type for this SPIR-V ID. id_to_type_[type_id] = ast_alias_type; @@ -1176,7 +1174,7 @@ bool ParserImpl::EmitModuleScopeVariables() { if (!success_) { return false; } - ast::type::Type* ast_type = nullptr; + type::Type* ast_type = nullptr; if (spirv_storage_class == SpvStorageClassUniformConstant) { // These are opaque handles: samplers or textures ast_type = GetTypeForHandleVar(var); @@ -1190,15 +1188,14 @@ bool ParserImpl::EmitModuleScopeVariables() { "SPIR-V type with ID: " << var.type_id(); } - if (!ast_type->Is()) { + if (!ast_type->Is()) { return Fail() << "variable with ID " << var.result_id() << " has non-pointer type " << var.type_id(); } } - auto* ast_store_type = ast_type->As()->type(); - auto ast_storage_class = - ast_type->As()->storage_class(); + auto* ast_store_type = ast_type->As()->type(); + auto ast_storage_class = ast_type->As()->storage_class(); ast::Expression* ast_constructor = nullptr; if (var.NumInOperands() > 1) { // SPIR-V initializers are always constants. @@ -1237,7 +1234,7 @@ bool ParserImpl::EmitModuleScopeVariables() { ast::Variable* ParserImpl::MakeVariable( uint32_t id, ast::StorageClass sc, - ast::type::Type* type, + type::Type* type, bool is_const, ast::Expression* constructor, ast::VariableDecorationList decorations) { @@ -1251,7 +1248,7 @@ ast::Variable* ParserImpl::MakeVariable( auto access = read_only_struct_types_.count(type) ? ast::AccessControl::kReadOnly : ast::AccessControl::kReadWrite; - type = ast_module_.create(access, type); + type = ast_module_.create(access, type); } for (auto& deco : GetDecorationsFor(id)) { @@ -1351,25 +1348,25 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { // So canonicalization should map that way too. // Currently "null" is missing from the WGSL parser. // See https://bugs.chromium.org/p/tint/issues/detail?id=34 - if (ast_type->Is()) { + if (ast_type->Is()) { return {ast_type, create( Source{}, create(source, ast_type, spirv_const->GetU32()))}; } - if (ast_type->Is()) { + if (ast_type->Is()) { return {ast_type, create( Source{}, create(source, ast_type, spirv_const->GetS32()))}; } - if (ast_type->Is()) { + if (ast_type->Is()) { return {ast_type, create( Source{}, create(source, ast_type, spirv_const->GetFloat()))}; } - if (ast_type->Is()) { + if (ast_type->Is()) { const bool value = spirv_const->AsNullConstant() ? false : spirv_const->AsBoolConstant()->value(); @@ -1413,7 +1410,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { return {}; } -ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { +ast::Expression* ParserImpl::MakeNullValue(type::Type* type) { // TODO(dneto): Use the no-operands constructor syntax when it becomes // available in Tint. // https://github.com/gpuweb/gpuweb/issues/685 @@ -1427,23 +1424,23 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { auto* original_type = type; type = type->UnwrapIfNeeded(); - if (type->Is()) { + if (type->Is()) { return create( Source{}, create(Source{}, type, false)); } - if (type->Is()) { + if (type->Is()) { return create( Source{}, create(Source{}, type, 0u)); } - if (type->Is()) { + if (type->Is()) { return create( Source{}, create(Source{}, type, 0)); } - if (type->Is()) { + if (type->Is()) { return create( Source{}, create(Source{}, type, 0.0f)); } - if (const auto* vec_ty = type->As()) { + if (const auto* vec_ty = type->As()) { ast::ExpressionList ast_components; for (size_t i = 0; i < vec_ty->size(); ++i) { ast_components.emplace_back(MakeNullValue(vec_ty->type())); @@ -1451,10 +1448,10 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { return create(Source{}, type, std::move(ast_components)); } - if (const auto* mat_ty = type->As()) { + if (const auto* mat_ty = type->As()) { // Matrix components are columns auto* column_ty = - ast_module_.create(mat_ty->type(), mat_ty->rows()); + ast_module_.create(mat_ty->type(), mat_ty->rows()); ast::ExpressionList ast_components; for (size_t i = 0; i < mat_ty->columns(); ++i) { ast_components.emplace_back(MakeNullValue(column_ty)); @@ -1462,7 +1459,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { return create(Source{}, type, std::move(ast_components)); } - if (auto* arr_ty = type->As()) { + if (auto* arr_ty = type->As()) { ast::ExpressionList ast_components; for (size_t i = 0; i < arr_ty->size(); ++i) { ast_components.emplace_back(MakeNullValue(arr_ty->type())); @@ -1470,7 +1467,7 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) { return create(Source{}, original_type, std::move(ast_components)); } - if (auto* struct_ty = type->As()) { + if (auto* struct_ty = type->As()) { ast::ExpressionList ast_components; for (auto* member : struct_ty->impl()->members()) { ast_components.emplace_back(MakeNullValue(member->type())); @@ -1529,9 +1526,8 @@ TypedExpression ParserImpl::RectifyOperandSignedness( return std::move(expr); } -ast::type::Type* ParserImpl::ForcedResultType( - const spvtools::opt::Instruction& inst, - ast::type::Type* first_operand_type) { +type::Type* ParserImpl::ForcedResultType(const spvtools::opt::Instruction& inst, + type::Type* first_operand_type) { const auto opcode = inst.opcode(); if (AssumesResultSignednessMatchesFirstOperand(opcode)) { return first_operand_type; @@ -1546,37 +1542,36 @@ ast::type::Type* ParserImpl::ForcedResultType( return nullptr; } -ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) { +type::Type* ParserImpl::GetSignedIntMatchingShape(type::Type* other) { if (other == nullptr) { Fail() << "no type provided"; } - auto* i32 = ast_module_.create(); - if (other->Is() || other->Is() || - other->Is()) { + auto* i32 = ast_module_.create(); + if (other->Is() || other->Is() || + other->Is()) { return i32; } - auto* vec_ty = other->As(); + auto* vec_ty = other->As(); if (vec_ty) { - return ast_module_.create(i32, vec_ty->size()); + return ast_module_.create(i32, vec_ty->size()); } Fail() << "required numeric scalar or vector, but got " << other->type_name(); return nullptr; } -ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape( - ast::type::Type* other) { +type::Type* ParserImpl::GetUnsignedIntMatchingShape(type::Type* other) { if (other == nullptr) { Fail() << "no type provided"; return nullptr; } - auto* u32 = ast_module_.create(); - if (other->Is() || other->Is() || - other->Is()) { + auto* u32 = ast_module_.create(); + if (other->Is() || other->Is() || + other->Is()) { return u32; } - auto* vec_ty = other->As(); + auto* vec_ty = other->As(); if (vec_ty) { - return ast_module_.create(u32, vec_ty->size()); + return ast_module_.create(u32, vec_ty->size()); } Fail() << "required numeric scalar or vector, but got " << other->type_name(); return nullptr; @@ -1585,7 +1580,7 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape( TypedExpression ParserImpl::RectifyForcedResultType( TypedExpression expr, const spvtools::opt::Instruction& inst, - ast::type::Type* first_operand_type) { + type::Type* first_operand_type) { auto* forced_result_ty = ForcedResultType(inst, first_operand_type); if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) { return expr; @@ -1764,7 +1759,7 @@ ParserImpl::GetSpirvTypeForHandleMemoryObjectDeclaration( return raw_handle_type; } -ast::type::Pointer* ParserImpl::GetTypeForHandleVar( +type::Pointer* ParserImpl::GetTypeForHandleVar( const spvtools::opt::Instruction& var) { auto where = handle_type_.find(&var); if (where != handle_type_.end()) { @@ -1848,11 +1843,11 @@ ast::type::Pointer* ParserImpl::GetTypeForHandleVar( } // Construct the Tint handle type. - ast::type::Type* ast_store_type = nullptr; + type::Type* ast_store_type = nullptr; if (usage.IsSampler()) { - ast_store_type = ast_module_.create( - usage.IsComparisonSampler() ? ast::type::SamplerKind::kComparisonSampler - : ast::type::SamplerKind::kSampler); + ast_store_type = ast_module_.create( + usage.IsComparisonSampler() ? type::SamplerKind::kComparisonSampler + : type::SamplerKind::kSampler); } else if (usage.IsTexture()) { const spvtools::opt::analysis::Image* image_type = type_mgr_->GetType(raw_handle_type->result_id())->AsImage(); @@ -1862,9 +1857,9 @@ ast::type::Pointer* ParserImpl::GetTypeForHandleVar( return nullptr; } - const ast::type::TextureDimension dim = + const type::TextureDimension dim = enum_converter_.ToDim(image_type->dim(), image_type->is_arrayed()); - if (dim == ast::type::TextureDimension::kNone) { + if (dim == type::TextureDimension::kNone) { return nullptr; } @@ -1881,13 +1876,13 @@ ast::type::Pointer* ParserImpl::GetTypeForHandleVar( // OpImage variable with an OpImage*Dref* instruction. In WGSL we must // treat that as a depth texture. if (image_type->depth() || usage.IsDepthTexture()) { - ast_store_type = ast_module_.create(dim); + ast_store_type = ast_module_.create(dim); } else if (image_type->is_multisampled()) { // Multisampled textures are never depth textures. - ast_store_type = ast_module_.create( + ast_store_type = ast_module_.create( dim, ast_sampled_component_type); } else { - ast_store_type = ast_module_.create( + ast_store_type = ast_module_.create( dim, ast_sampled_component_type); } } else { @@ -1895,11 +1890,11 @@ ast::type::Pointer* ParserImpl::GetTypeForHandleVar( ? ast::AccessControl::kReadOnly : ast::AccessControl::kWriteOnly; const auto format = enum_converter_.ToImageFormat(image_type->format()); - if (format == ast::type::ImageFormat::kNone) { + if (format == type::ImageFormat::kNone) { return nullptr; } - ast_store_type = ast_module_.create( - access, ast_module_.create(dim, format)); + ast_store_type = ast_module_.create( + access, ast_module_.create(dim, format)); } } else { Fail() << "unsupported: UniformConstant variable is not a recognized " @@ -1909,56 +1904,55 @@ ast::type::Pointer* ParserImpl::GetTypeForHandleVar( } // Form the pointer type. - auto* result = ast_module_.create( + auto* result = ast_module_.create( ast_store_type, ast::StorageClass::kUniformConstant); // Remember it for later. handle_type_[&var] = result; return result; } -ast::type::Type* ParserImpl::GetComponentTypeForFormat( - ast::type::ImageFormat format) { +type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) { switch (format) { - case ast::type::ImageFormat::kR8Uint: - case ast::type::ImageFormat::kR16Uint: - case ast::type::ImageFormat::kRg8Uint: - case ast::type::ImageFormat::kR32Uint: - case ast::type::ImageFormat::kRg16Uint: - case ast::type::ImageFormat::kRgba8Uint: - case ast::type::ImageFormat::kRg32Uint: - case ast::type::ImageFormat::kRgba16Uint: - case ast::type::ImageFormat::kRgba32Uint: - return ast_module_.create(); + case type::ImageFormat::kR8Uint: + case type::ImageFormat::kR16Uint: + case type::ImageFormat::kRg8Uint: + case type::ImageFormat::kR32Uint: + case type::ImageFormat::kRg16Uint: + case type::ImageFormat::kRgba8Uint: + case type::ImageFormat::kRg32Uint: + case type::ImageFormat::kRgba16Uint: + case type::ImageFormat::kRgba32Uint: + return ast_module_.create(); - case ast::type::ImageFormat::kR8Sint: - case ast::type::ImageFormat::kR16Sint: - case ast::type::ImageFormat::kRg8Sint: - case ast::type::ImageFormat::kR32Sint: - case ast::type::ImageFormat::kRg16Sint: - case ast::type::ImageFormat::kRgba8Sint: - case ast::type::ImageFormat::kRg32Sint: - case ast::type::ImageFormat::kRgba16Sint: - case ast::type::ImageFormat::kRgba32Sint: - return ast_module_.create(); + case type::ImageFormat::kR8Sint: + case type::ImageFormat::kR16Sint: + case type::ImageFormat::kRg8Sint: + case type::ImageFormat::kR32Sint: + case type::ImageFormat::kRg16Sint: + case type::ImageFormat::kRgba8Sint: + case type::ImageFormat::kRg32Sint: + case type::ImageFormat::kRgba16Sint: + case type::ImageFormat::kRgba32Sint: + return ast_module_.create(); - case ast::type::ImageFormat::kR8Unorm: - case ast::type::ImageFormat::kRg8Unorm: - case ast::type::ImageFormat::kRgba8Unorm: - case ast::type::ImageFormat::kRgba8UnormSrgb: - case ast::type::ImageFormat::kBgra8Unorm: - case ast::type::ImageFormat::kBgra8UnormSrgb: - case ast::type::ImageFormat::kRgb10A2Unorm: - case ast::type::ImageFormat::kR8Snorm: - case ast::type::ImageFormat::kRg8Snorm: - case ast::type::ImageFormat::kRgba8Snorm: - case ast::type::ImageFormat::kR16Float: - case ast::type::ImageFormat::kR32Float: - case ast::type::ImageFormat::kRg16Float: - case ast::type::ImageFormat::kRg11B10Float: - case ast::type::ImageFormat::kRg32Float: - case ast::type::ImageFormat::kRgba16Float: - case ast::type::ImageFormat::kRgba32Float: - return ast_module_.create(); + case type::ImageFormat::kR8Unorm: + case type::ImageFormat::kRg8Unorm: + case type::ImageFormat::kRgba8Unorm: + case type::ImageFormat::kRgba8UnormSrgb: + case type::ImageFormat::kBgra8Unorm: + case type::ImageFormat::kBgra8UnormSrgb: + case type::ImageFormat::kRgb10A2Unorm: + case type::ImageFormat::kR8Snorm: + case type::ImageFormat::kRg8Snorm: + case type::ImageFormat::kRgba8Snorm: + case type::ImageFormat::kR16Float: + case type::ImageFormat::kR32Float: + case type::ImageFormat::kRg16Float: + case type::ImageFormat::kRg11B10Float: + case type::ImageFormat::kRg32Float: + case type::ImageFormat::kRgba16Float: + case type::ImageFormat::kRgba32Float: + return ast_module_.create(); default: break; } @@ -1966,57 +1960,56 @@ ast::type::Type* ParserImpl::GetComponentTypeForFormat( return nullptr; } -ast::type::Type* ParserImpl::GetTexelTypeForFormat( - ast::type::ImageFormat format) { +type::Type* ParserImpl::GetTexelTypeForFormat(type::ImageFormat format) { auto* component_type = GetComponentTypeForFormat(format); if (!component_type) { return nullptr; } switch (format) { - case ast::type::ImageFormat::kR16Float: - case ast::type::ImageFormat::kR16Sint: - case ast::type::ImageFormat::kR16Uint: - case ast::type::ImageFormat::kR32Float: - case ast::type::ImageFormat::kR32Sint: - case ast::type::ImageFormat::kR32Uint: - case ast::type::ImageFormat::kR8Sint: - case ast::type::ImageFormat::kR8Snorm: - case ast::type::ImageFormat::kR8Uint: - case ast::type::ImageFormat::kR8Unorm: + case type::ImageFormat::kR16Float: + case type::ImageFormat::kR16Sint: + case type::ImageFormat::kR16Uint: + case type::ImageFormat::kR32Float: + case type::ImageFormat::kR32Sint: + case type::ImageFormat::kR32Uint: + case type::ImageFormat::kR8Sint: + case type::ImageFormat::kR8Snorm: + case type::ImageFormat::kR8Uint: + case type::ImageFormat::kR8Unorm: // One channel return component_type; - case ast::type::ImageFormat::kRg11B10Float: - case ast::type::ImageFormat::kRg16Float: - case ast::type::ImageFormat::kRg16Sint: - case ast::type::ImageFormat::kRg16Uint: - case ast::type::ImageFormat::kRg32Float: - case ast::type::ImageFormat::kRg32Sint: - case ast::type::ImageFormat::kRg32Uint: - case ast::type::ImageFormat::kRg8Sint: - case ast::type::ImageFormat::kRg8Snorm: - case ast::type::ImageFormat::kRg8Uint: - case ast::type::ImageFormat::kRg8Unorm: + case type::ImageFormat::kRg11B10Float: + case type::ImageFormat::kRg16Float: + case type::ImageFormat::kRg16Sint: + case type::ImageFormat::kRg16Uint: + case type::ImageFormat::kRg32Float: + case type::ImageFormat::kRg32Sint: + case type::ImageFormat::kRg32Uint: + case type::ImageFormat::kRg8Sint: + case type::ImageFormat::kRg8Snorm: + case type::ImageFormat::kRg8Uint: + case type::ImageFormat::kRg8Unorm: // Two channels - return ast_module_.create(component_type, 2); + return ast_module_.create(component_type, 2); - case ast::type::ImageFormat::kBgra8Unorm: - case ast::type::ImageFormat::kBgra8UnormSrgb: - case ast::type::ImageFormat::kRgb10A2Unorm: - case ast::type::ImageFormat::kRgba16Float: - case ast::type::ImageFormat::kRgba16Sint: - case ast::type::ImageFormat::kRgba16Uint: - case ast::type::ImageFormat::kRgba32Float: - case ast::type::ImageFormat::kRgba32Sint: - case ast::type::ImageFormat::kRgba32Uint: - case ast::type::ImageFormat::kRgba8Sint: - case ast::type::ImageFormat::kRgba8Snorm: - case ast::type::ImageFormat::kRgba8Uint: - case ast::type::ImageFormat::kRgba8Unorm: - case ast::type::ImageFormat::kRgba8UnormSrgb: + case type::ImageFormat::kBgra8Unorm: + case type::ImageFormat::kBgra8UnormSrgb: + case type::ImageFormat::kRgb10A2Unorm: + case type::ImageFormat::kRgba16Float: + case type::ImageFormat::kRgba16Sint: + case type::ImageFormat::kRgba16Uint: + case type::ImageFormat::kRgba32Float: + case type::ImageFormat::kRgba32Sint: + case type::ImageFormat::kRgba32Uint: + case type::ImageFormat::kRgba8Sint: + case type::ImageFormat::kRgba8Snorm: + case type::ImageFormat::kRgba8Uint: + case type::ImageFormat::kRgba8Unorm: + case type::ImageFormat::kRgba8UnormSrgb: // Four channels - return ast_module_.create(component_type, 4); + return ast_module_.create(component_type, 4); default: break; diff --git a/src/reader/spirv/parser_impl.h b/src/reader/spirv/parser_impl.h index c832a055cd..bc858626b4 100644 --- a/src/reader/spirv/parser_impl.h +++ b/src/reader/spirv/parser_impl.h @@ -34,10 +34,6 @@ #include "src/ast/expression.h" #include "src/ast/module.h" #include "src/ast/struct_member_decoration.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/type.h" #include "src/reader/reader.h" #include "src/reader/spirv/entry_point_info.h" #include "src/reader/spirv/enum_converter.h" @@ -45,6 +41,10 @@ #include "src/reader/spirv/namer.h" #include "src/reader/spirv/usage.h" #include "src/source.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/pointer_type.h" +#include "src/type/type.h" /// This is the implementation of the SPIR-V parser for Tint. @@ -77,7 +77,7 @@ using DecorationList = std::vector; /// An AST expression with its type. struct TypedExpression { /// The type - ast::type::Type* type = nullptr; + type::Type* type = nullptr; /// The expression ast::Expression* expr = nullptr; }; @@ -147,7 +147,7 @@ class ParserImpl : Reader { /// after the internal representation of the module has been built. /// @param type_id the SPIR-V ID of a type. /// @returns a Tint type, or nullptr - ast::type::Type* ConvertType(uint32_t type_id); + type::Type* ConvertType(uint32_t type_id); /// Emits an alias type declaration for the given type, if necessary, and /// also updates the mapping of the SPIR-V type ID to the alias type. @@ -298,7 +298,7 @@ class ParserImpl : Reader { /// in the error case ast::Variable* MakeVariable(uint32_t id, ast::StorageClass sc, - ast::type::Type* type, + type::Type* type, bool is_const, ast::Expression* constructor, ast::VariableDecorationList decorations); @@ -311,7 +311,7 @@ class ParserImpl : Reader { /// Creates an AST expression node for the null value for the given type. /// @param type the AST type /// @returns a new expression - ast::Expression* MakeNullValue(ast::type::Type* type); + ast::Expression* MakeNullValue(type::Type* type); /// Converts a given expression to the signedness demanded for an operand /// of the given SPIR-V instruction, if required. If the instruction assumes @@ -334,8 +334,8 @@ class ParserImpl : Reader { /// @param inst the SPIR-V instruction /// @param first_operand_type the AST type for the first operand. /// @returns the forced AST result type, or nullptr if no forcing is required. - ast::type::Type* ForcedResultType(const spvtools::opt::Instruction& inst, - ast::type::Type* first_operand_type); + type::Type* ForcedResultType(const spvtools::opt::Instruction& inst, + type::Type* first_operand_type); /// Returns a signed integer scalar or vector type matching the shape (scalar, /// vector, and component bit width) of another type, which itself is a @@ -343,7 +343,7 @@ class ParserImpl : Reader { /// requirement. /// @param other the type whose shape must be matched /// @returns the signed scalar or vector type - ast::type::Type* GetSignedIntMatchingShape(ast::type::Type* other); + type::Type* GetSignedIntMatchingShape(type::Type* other); /// Returns a signed integer scalar or vector type matching the shape (scalar, /// vector, and component bit width) of another type, which itself is a @@ -351,7 +351,7 @@ class ParserImpl : Reader { /// requirement. /// @param other the type whose shape must be matched /// @returns the unsigned scalar or vector type - ast::type::Type* GetUnsignedIntMatchingShape(ast::type::Type* other); + type::Type* GetUnsignedIntMatchingShape(type::Type* other); /// Wraps the given expression in an as-cast to the given expression's type, /// when the underlying operation produces a forced result type different @@ -364,10 +364,10 @@ class ParserImpl : Reader { TypedExpression RectifyForcedResultType( TypedExpression expr, const spvtools::opt::Instruction& inst, - ast::type::Type* first_operand_type); + type::Type* first_operand_type); /// @returns the registered boolean type. - ast::type::Type* Bool() const { return bool_type_; } + type::Type* Bool() const { return bool_type_; } /// Bookkeeping used for tracking the "position" builtin variable. struct BuiltInPositionInfo { @@ -455,19 +455,18 @@ class ParserImpl : Reader { /// @param var the OpVariable instruction /// @returns the Tint AST type for the poiner-to-{sampler|texture} or null on /// error - ast::type::Pointer* GetTypeForHandleVar( - const spvtools::opt::Instruction& var); + type::Pointer* GetTypeForHandleVar(const spvtools::opt::Instruction& var); /// Returns the channel component type corresponding to the given image /// format. /// @param format image texel format /// @returns the component type, one of f32, i32, u32 - ast::type::Type* GetComponentTypeForFormat(ast::type::ImageFormat format); + type::Type* GetComponentTypeForFormat(type::ImageFormat format); /// Returns texel type corresponding to the given image format. /// @param format image texel format /// @returns the texel format - ast::type::Type* GetTexelTypeForFormat(ast::type::ImageFormat format); + type::Type* GetTexelTypeForFormat(type::ImageFormat format); /// Returns the SPIR-V instruction with the given ID, or nullptr. /// @param id the SPIR-V result ID @@ -483,20 +482,20 @@ class ParserImpl : Reader { private: /// Converts a specific SPIR-V type to a Tint type. Integer case - ast::type::Type* ConvertType(const spvtools::opt::analysis::Integer* int_ty); + type::Type* ConvertType(const spvtools::opt::analysis::Integer* int_ty); /// Converts a specific SPIR-V type to a Tint type. Float case - ast::type::Type* ConvertType(const spvtools::opt::analysis::Float* float_ty); + type::Type* ConvertType(const spvtools::opt::analysis::Float* float_ty); /// Converts a specific SPIR-V type to a Tint type. Vector case - ast::type::Type* ConvertType(const spvtools::opt::analysis::Vector* vec_ty); + type::Type* ConvertType(const spvtools::opt::analysis::Vector* vec_ty); /// Converts a specific SPIR-V type to a Tint type. Matrix case - ast::type::Type* ConvertType(const spvtools::opt::analysis::Matrix* mat_ty); + type::Type* ConvertType(const spvtools::opt::analysis::Matrix* mat_ty); /// Converts a specific SPIR-V type to a Tint type. RuntimeArray case /// @param rtarr_ty the Tint type - ast::type::Type* ConvertType( + type::Type* ConvertType( const spvtools::opt::analysis::RuntimeArray* rtarr_ty); /// Converts a specific SPIR-V type to a Tint type. Array case /// @param arr_ty the Tint type - ast::type::Type* ConvertType(const spvtools::opt::analysis::Array* arr_ty); + type::Type* ConvertType(const spvtools::opt::analysis::Array* arr_ty); /// Converts a specific SPIR-V type to a Tint type. Struct case. /// SPIR-V allows distinct struct type definitions for two OpTypeStruct /// that otherwise have the same set of members (and struct and member @@ -508,16 +507,15 @@ class ParserImpl : Reader { /// not significant to the optimizer's module representation. /// @param type_id the SPIR-V ID for the type. /// @param struct_ty the Tint type - ast::type::Type* ConvertType( - uint32_t type_id, - const spvtools::opt::analysis::Struct* struct_ty); + type::Type* ConvertType(uint32_t type_id, + const spvtools::opt::analysis::Struct* struct_ty); /// Converts a specific SPIR-V type to a Tint type. Pointer case /// The pointer to gl_PerVertex maps to nullptr, and instead is recorded /// in member #builtin_position_. /// @param type_id the SPIR-V ID for the type. /// @param ptr_ty the Tint type - ast::type::Type* ConvertType(uint32_t type_id, - const spvtools::opt::analysis::Pointer* ptr_ty); + type::Type* ConvertType(uint32_t type_id, + const spvtools::opt::analysis::Pointer* ptr_ty); /// Parses the array or runtime-array decorations. /// @param spv_type the SPIR-V array or runtime-array type. @@ -549,7 +547,7 @@ class ParserImpl : Reader { spvtools::MessageConsumer message_consumer_; // The registered boolean type. - ast::type::Type* bool_type_; + type::Type* bool_type_; // An object used to store and generate names for SPIR-V objects. Namer namer_; @@ -582,12 +580,12 @@ class ParserImpl : Reader { std::unordered_set glsl_std_450_imports_; // Maps a SPIR-V type ID to the corresponding Tint type. - std::unordered_map id_to_type_; + std::unordered_map id_to_type_; // Maps an unsigned type corresponding to the given signed type. - std::unordered_map signed_type_for_; + std::unordered_map signed_type_for_; // Maps an signed type corresponding to the given unsigned type. - std::unordered_map unsigned_type_for_; + std::unordered_map unsigned_type_for_; // Bookkeeping for the gl_Position builtin. // In Vulkan SPIR-V, it's the 0 member of the gl_PerVertex structure. @@ -607,7 +605,7 @@ class ParserImpl : Reader { std::unordered_set remap_buffer_block_type_; // The struct types with only read-only members. - std::unordered_set read_only_struct_types_; + std::unordered_set read_only_struct_types_; // The IDs of scalar spec constants std::unordered_set scalar_spec_constants_; @@ -632,7 +630,7 @@ class ParserImpl : Reader { // usages implied by usages of the memory-object-declaration. std::unordered_map handle_usage_; // The inferred pointer type for the given handle variable. - std::unordered_map + std::unordered_map handle_type_; /// Maps the SPIR-V ID of a module-scope builtin variable that should be diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index 99bf39370b..cc871c05ed 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -18,20 +18,20 @@ #include "gmock/gmock.h" #include "src/ast/struct.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/spirv_tools_helpers_test.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { namespace reader { @@ -92,7 +92,7 @@ TEST_F(SpvParserTest, ConvertType_Void) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(1); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -101,7 +101,7 @@ TEST_F(SpvParserTest, ConvertType_Bool) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(100); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -110,7 +110,7 @@ TEST_F(SpvParserTest, ConvertType_I32) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(2); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -119,7 +119,7 @@ TEST_F(SpvParserTest, ConvertType_U32) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -128,7 +128,7 @@ TEST_F(SpvParserTest, ConvertType_F32) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(4); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -172,19 +172,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverF32) { EXPECT_TRUE(p->BuildInternalModule()); auto* v2xf32 = p->ConvertType(20); - EXPECT_TRUE(v2xf32->Is()); - EXPECT_TRUE(v2xf32->As()->type()->Is()); - EXPECT_EQ(v2xf32->As()->size(), 2u); + EXPECT_TRUE(v2xf32->Is()); + EXPECT_TRUE(v2xf32->As()->type()->Is()); + EXPECT_EQ(v2xf32->As()->size(), 2u); auto* v3xf32 = p->ConvertType(30); - EXPECT_TRUE(v3xf32->Is()); - EXPECT_TRUE(v3xf32->As()->type()->Is()); - EXPECT_EQ(v3xf32->As()->size(), 3u); + EXPECT_TRUE(v3xf32->Is()); + EXPECT_TRUE(v3xf32->As()->type()->Is()); + EXPECT_EQ(v3xf32->As()->size(), 3u); auto* v4xf32 = p->ConvertType(40); - EXPECT_TRUE(v4xf32->Is()); - EXPECT_TRUE(v4xf32->As()->type()->Is()); - EXPECT_EQ(v4xf32->As()->size(), 4u); + EXPECT_TRUE(v4xf32->Is()); + EXPECT_TRUE(v4xf32->As()->type()->Is()); + EXPECT_EQ(v4xf32->As()->size(), 4u); EXPECT_TRUE(p->error().empty()); } @@ -199,19 +199,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverI32) { EXPECT_TRUE(p->BuildInternalModule()); auto* v2xi32 = p->ConvertType(20); - EXPECT_TRUE(v2xi32->Is()); - EXPECT_TRUE(v2xi32->As()->type()->Is()); - EXPECT_EQ(v2xi32->As()->size(), 2u); + EXPECT_TRUE(v2xi32->Is()); + EXPECT_TRUE(v2xi32->As()->type()->Is()); + EXPECT_EQ(v2xi32->As()->size(), 2u); auto* v3xi32 = p->ConvertType(30); - EXPECT_TRUE(v3xi32->Is()); - EXPECT_TRUE(v3xi32->As()->type()->Is()); - EXPECT_EQ(v3xi32->As()->size(), 3u); + EXPECT_TRUE(v3xi32->Is()); + EXPECT_TRUE(v3xi32->As()->type()->Is()); + EXPECT_EQ(v3xi32->As()->size(), 3u); auto* v4xi32 = p->ConvertType(40); - EXPECT_TRUE(v4xi32->Is()); - EXPECT_TRUE(v4xi32->As()->type()->Is()); - EXPECT_EQ(v4xi32->As()->size(), 4u); + EXPECT_TRUE(v4xi32->Is()); + EXPECT_TRUE(v4xi32->As()->type()->Is()); + EXPECT_EQ(v4xi32->As()->size(), 4u); EXPECT_TRUE(p->error().empty()); } @@ -226,19 +226,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) { EXPECT_TRUE(p->BuildInternalModule()); auto* v2xu32 = p->ConvertType(20); - EXPECT_TRUE(v2xu32->Is()); - EXPECT_TRUE(v2xu32->As()->type()->Is()); - EXPECT_EQ(v2xu32->As()->size(), 2u); + EXPECT_TRUE(v2xu32->Is()); + EXPECT_TRUE(v2xu32->As()->type()->Is()); + EXPECT_EQ(v2xu32->As()->size(), 2u); auto* v3xu32 = p->ConvertType(30); - EXPECT_TRUE(v3xu32->Is()); - EXPECT_TRUE(v3xu32->As()->type()->Is()); - EXPECT_EQ(v3xu32->As()->size(), 3u); + EXPECT_TRUE(v3xu32->Is()); + EXPECT_TRUE(v3xu32->As()->type()->Is()); + EXPECT_EQ(v3xu32->As()->size(), 3u); auto* v4xu32 = p->ConvertType(40); - EXPECT_TRUE(v4xu32->Is()); - EXPECT_TRUE(v4xu32->As()->type()->Is()); - EXPECT_EQ(v4xu32->As()->size(), 4u); + EXPECT_TRUE(v4xu32->Is()); + EXPECT_TRUE(v4xu32->As()->type()->Is()); + EXPECT_EQ(v4xu32->As()->size(), 4u); EXPECT_TRUE(p->error().empty()); } @@ -278,58 +278,58 @@ TEST_F(SpvParserTest, ConvertType_MatrixOverF32) { EXPECT_TRUE(p->BuildInternalModule()); auto* m22 = p->ConvertType(22); - EXPECT_TRUE(m22->Is()); - EXPECT_TRUE(m22->As()->type()->Is()); - EXPECT_EQ(m22->As()->rows(), 2u); - EXPECT_EQ(m22->As()->columns(), 2u); + EXPECT_TRUE(m22->Is()); + EXPECT_TRUE(m22->As()->type()->Is()); + EXPECT_EQ(m22->As()->rows(), 2u); + EXPECT_EQ(m22->As()->columns(), 2u); auto* m23 = p->ConvertType(23); - EXPECT_TRUE(m23->Is()); - EXPECT_TRUE(m23->As()->type()->Is()); - EXPECT_EQ(m23->As()->rows(), 2u); - EXPECT_EQ(m23->As()->columns(), 3u); + EXPECT_TRUE(m23->Is()); + EXPECT_TRUE(m23->As()->type()->Is()); + EXPECT_EQ(m23->As()->rows(), 2u); + EXPECT_EQ(m23->As()->columns(), 3u); auto* m24 = p->ConvertType(24); - EXPECT_TRUE(m24->Is()); - EXPECT_TRUE(m24->As()->type()->Is()); - EXPECT_EQ(m24->As()->rows(), 2u); - EXPECT_EQ(m24->As()->columns(), 4u); + EXPECT_TRUE(m24->Is()); + EXPECT_TRUE(m24->As()->type()->Is()); + EXPECT_EQ(m24->As()->rows(), 2u); + EXPECT_EQ(m24->As()->columns(), 4u); auto* m32 = p->ConvertType(32); - EXPECT_TRUE(m32->Is()); - EXPECT_TRUE(m32->As()->type()->Is()); - EXPECT_EQ(m32->As()->rows(), 3u); - EXPECT_EQ(m32->As()->columns(), 2u); + EXPECT_TRUE(m32->Is()); + EXPECT_TRUE(m32->As()->type()->Is()); + EXPECT_EQ(m32->As()->rows(), 3u); + EXPECT_EQ(m32->As()->columns(), 2u); auto* m33 = p->ConvertType(33); - EXPECT_TRUE(m33->Is()); - EXPECT_TRUE(m33->As()->type()->Is()); - EXPECT_EQ(m33->As()->rows(), 3u); - EXPECT_EQ(m33->As()->columns(), 3u); + EXPECT_TRUE(m33->Is()); + EXPECT_TRUE(m33->As()->type()->Is()); + EXPECT_EQ(m33->As()->rows(), 3u); + EXPECT_EQ(m33->As()->columns(), 3u); auto* m34 = p->ConvertType(34); - EXPECT_TRUE(m34->Is()); - EXPECT_TRUE(m34->As()->type()->Is()); - EXPECT_EQ(m34->As()->rows(), 3u); - EXPECT_EQ(m34->As()->columns(), 4u); + EXPECT_TRUE(m34->Is()); + EXPECT_TRUE(m34->As()->type()->Is()); + EXPECT_EQ(m34->As()->rows(), 3u); + EXPECT_EQ(m34->As()->columns(), 4u); auto* m42 = p->ConvertType(42); - EXPECT_TRUE(m42->Is()); - EXPECT_TRUE(m42->As()->type()->Is()); - EXPECT_EQ(m42->As()->rows(), 4u); - EXPECT_EQ(m42->As()->columns(), 2u); + EXPECT_TRUE(m42->Is()); + EXPECT_TRUE(m42->As()->type()->Is()); + EXPECT_EQ(m42->As()->rows(), 4u); + EXPECT_EQ(m42->As()->columns(), 2u); auto* m43 = p->ConvertType(43); - EXPECT_TRUE(m43->Is()); - EXPECT_TRUE(m43->As()->type()->Is()); - EXPECT_EQ(m43->As()->rows(), 4u); - EXPECT_EQ(m43->As()->columns(), 3u); + EXPECT_TRUE(m43->Is()); + EXPECT_TRUE(m43->As()->type()->Is()); + EXPECT_EQ(m43->As()->rows(), 4u); + EXPECT_EQ(m43->As()->columns(), 3u); auto* m44 = p->ConvertType(44); - EXPECT_TRUE(m44->Is()); - EXPECT_TRUE(m44->As()->type()->Is()); - EXPECT_EQ(m44->As()->rows(), 4u); - EXPECT_EQ(m44->As()->columns(), 4u); + EXPECT_TRUE(m44->Is()); + EXPECT_TRUE(m44->As()->type()->Is()); + EXPECT_EQ(m44->As()->rows(), 4u); + EXPECT_EQ(m44->As()->columns(), 4u); EXPECT_TRUE(p->error().empty()); } @@ -343,8 +343,8 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); - auto* arr_type = type->As(); + EXPECT_TRUE(type->Is()); + auto* arr_type = type->As(); EXPECT_TRUE(arr_type->IsRuntimeArray()); ASSERT_NE(arr_type, nullptr); EXPECT_EQ(arr_type->size(), 0u); @@ -352,7 +352,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) { EXPECT_FALSE(arr_type->has_array_stride()); auto* elem_type = arr_type->type(); ASSERT_NE(elem_type, nullptr); - EXPECT_TRUE(elem_type->Is()); + EXPECT_TRUE(elem_type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -379,7 +379,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray_ArrayStride_Valid) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - auto* arr_type = type->As(); + auto* arr_type = type->As(); EXPECT_TRUE(arr_type->IsRuntimeArray()); ASSERT_NE(arr_type, nullptr); EXPECT_EQ(arr_type->array_stride(), 64u); @@ -425,8 +425,8 @@ TEST_F(SpvParserTest, ConvertType_Array) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); - auto* arr_type = type->As(); + EXPECT_TRUE(type->Is()); + auto* arr_type = type->As(); EXPECT_FALSE(arr_type->IsRuntimeArray()); ASSERT_NE(arr_type, nullptr); EXPECT_EQ(arr_type->size(), 42u); @@ -434,7 +434,7 @@ TEST_F(SpvParserTest, ConvertType_Array) { EXPECT_FALSE(arr_type->has_array_stride()); auto* elem_type = arr_type->type(); ASSERT_NE(elem_type, nullptr); - EXPECT_TRUE(elem_type->Is()); + EXPECT_TRUE(elem_type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -513,8 +513,8 @@ TEST_F(SpvParserTest, ConvertType_ArrayStride_Valid) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); - auto* arr_type = type->As(); + EXPECT_TRUE(type->Is()); + auto* arr_type = type->As(); ASSERT_NE(arr_type, nullptr); ASSERT_EQ(arr_type->array_stride(), 8u); EXPECT_TRUE(arr_type->has_array_stride()); @@ -563,9 +563,9 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); std::stringstream ss; - type->As()->impl()->to_str(ss, 0); + type->As()->impl()->to_str(ss, 0); EXPECT_THAT(Demangler().Demangle(p->get_module(), ss.str()), Eq(R"(Struct{ StructMember{field0: __u32} StructMember{field1: __f32} @@ -584,9 +584,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); std::stringstream ss; - type->As()->impl()->to_str(ss, 0); + type->As()->impl()->to_str(ss, 0); EXPECT_THAT(Demangler().Demangle(p->get_module(), ss.str()), Eq(R"(Struct{ [[block]] StructMember{field0: __u32} @@ -609,9 +609,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) { auto* type = p->ConvertType(10); ASSERT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); std::stringstream ss; - type->As()->impl()->to_str(ss, 0); + type->As()->impl()->to_str(ss, 0); EXPECT_THAT(Demangler().Demangle(p->get_module(), ss.str()), Eq(R"(Struct{ StructMember{[[ offset 0 ]] field0: __f32} StructMember{[[ offset 8 ]] field1: __vec_2__f32} @@ -658,10 +658,10 @@ TEST_F(SpvParserTest, ConvertType_PointerInput) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput); EXPECT_TRUE(p->error().empty()); } @@ -674,10 +674,10 @@ TEST_F(SpvParserTest, ConvertType_PointerOutput) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kOutput); EXPECT_TRUE(p->error().empty()); } @@ -690,10 +690,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniform) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniform); EXPECT_TRUE(p->error().empty()); } @@ -706,10 +706,10 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kWorkgroup); EXPECT_TRUE(p->error().empty()); } @@ -722,10 +722,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniformConstant) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniformConstant); EXPECT_TRUE(p->error().empty()); } @@ -738,10 +738,10 @@ TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kStorage); EXPECT_TRUE(p->error().empty()); } @@ -754,10 +754,10 @@ TEST_F(SpvParserTest, ConvertType_PointerImage) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kImage); EXPECT_TRUE(p->error().empty()); } @@ -770,10 +770,10 @@ TEST_F(SpvParserTest, ConvertType_PointerPrivate) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kPrivate); EXPECT_TRUE(p->error().empty()); } @@ -786,10 +786,10 @@ TEST_F(SpvParserTest, ConvertType_PointerFunction) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(3); - EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + EXPECT_TRUE(type->Is()); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kFunction); EXPECT_TRUE(p->error().empty()); } @@ -805,17 +805,17 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) { auto* type = p->ConvertType(3); EXPECT_NE(type, nullptr); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); - auto* ptr_ty = type->As(); + auto* ptr_ty = type->As(); EXPECT_NE(ptr_ty, nullptr); EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput); - EXPECT_TRUE(ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ty->type()->Is()); - auto* ptr_ptr_ty = ptr_ty->type()->As(); + auto* ptr_ptr_ty = ptr_ty->type()->As(); EXPECT_NE(ptr_ptr_ty, nullptr); EXPECT_EQ(ptr_ptr_ty->storage_class(), ast::StorageClass::kOutput); - EXPECT_TRUE(ptr_ptr_ty->type()->Is()); + EXPECT_TRUE(ptr_ptr_ty->type()->Is()); EXPECT_TRUE(p->error().empty()); } @@ -828,7 +828,7 @@ TEST_F(SpvParserTest, ConvertType_Sampler_PretendVoid) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(1); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -841,7 +841,7 @@ TEST_F(SpvParserTest, ConvertType_Image_PretendVoid) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(1); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } @@ -854,7 +854,7 @@ TEST_F(SpvParserTest, ConvertType_SampledImage_PretendVoid) { EXPECT_TRUE(p->BuildInternalModule()); auto* type = p->ConvertType(1); - EXPECT_TRUE(type->Is()); + EXPECT_TRUE(type->Is()); EXPECT_TRUE(p->error().empty()); } diff --git a/src/reader/spirv/parser_impl_named_types_test.cc b/src/reader/spirv/parser_impl_named_types_test.cc index 26a3e3cb35..13f9af90ea 100644 --- a/src/reader/spirv/parser_impl_named_types_test.cc +++ b/src/reader/spirv/parser_impl_named_types_test.cc @@ -18,10 +18,10 @@ #include "gmock/gmock.h" #include "src/ast/struct.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/array_type.h" +#include "src/type/matrix_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" #include "src/demangler.h" #include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl_test_helper.h" diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 264f23fe07..3d56aaf04c 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -45,22 +45,6 @@ #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/type_decoration.h" #include "src/ast/uint_literal.h" @@ -70,6 +54,22 @@ #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" #include "src/reader/wgsl/lexer.h" +#include "src/type/access_control_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { namespace reader { @@ -196,7 +196,7 @@ ParserImpl::FunctionHeader::FunctionHeader(const FunctionHeader&) = default; ParserImpl::FunctionHeader::FunctionHeader(Source src, std::string n, ast::VariableList p, - ast::type::Type* ret_ty) + type::Type* ret_ty) : source(src), name(n), params(p), return_type(ret_ty) {} ParserImpl::FunctionHeader::~FunctionHeader() = default; @@ -260,12 +260,12 @@ Token ParserImpl::peek() { } void ParserImpl::register_constructed(const std::string& name, - ast::type::Type* type) { + type::Type* type) { assert(type); registered_constructs_[name] = type; } -ast::type::Type* ParserImpl::get_constructed(const std::string& name) { +type::Type* ParserImpl::get_constructed(const std::string& name) { if (registered_constructs_.find(name) == registered_constructs_.end()) { return nullptr; } @@ -361,7 +361,7 @@ Expect ParserImpl::expect_global_decl() { auto* type = module_.unique_type(std::move(str.value)); register_constructed( - module_.SymbolToName(type->As()->symbol()), type); + module_.SymbolToName(type->As()->symbol()), type); module_.AddConstructedType(type); return true; } @@ -497,7 +497,7 @@ Maybe ParserImpl::variable_decl() { // | sampled_texture_type LESS_THAN type_decl GREATER_THAN // | multisampled_texture_type LESS_THAN type_decl GREATER_THAN // | storage_texture_type LESS_THAN image_storage_type GREATER_THAN -Maybe ParserImpl::texture_sampler_types() { +Maybe ParserImpl::texture_sampler_types() { auto type = sampler_type(); if (type.matched) return type; @@ -514,7 +514,7 @@ Maybe ParserImpl::texture_sampler_types() { if (subtype.errored) return Failure::kErrored; - return module_.create(dim.value, subtype.value); + return module_.create(dim.value, subtype.value); } auto ms_dim = multisampled_texture_type(); @@ -525,8 +525,8 @@ Maybe ParserImpl::texture_sampler_types() { if (subtype.errored) return Failure::kErrored; - return module_.create(ms_dim.value, - subtype.value); + return module_.create(ms_dim.value, + subtype.value); } auto storage = storage_texture_type(); @@ -539,8 +539,7 @@ Maybe ParserImpl::texture_sampler_types() { if (format.errored) return Failure::kErrored; - return module_.create(storage.value, - format.value); + return module_.create(storage.value, format.value); } // DEPRECATED @@ -554,9 +553,9 @@ Maybe ParserImpl::texture_sampler_types() { if (format.errored) return Failure::kErrored; - return module_.create( - ac_storage->second, module_.create( - ac_storage->first, format.value)); + return module_.create( + ac_storage->second, + module_.create(ac_storage->first, format.value)); } return Failure::kNoMatch; @@ -565,13 +564,12 @@ Maybe ParserImpl::texture_sampler_types() { // sampler_type // : SAMPLER // | SAMPLER_COMPARISON -Maybe ParserImpl::sampler_type() { +Maybe ParserImpl::sampler_type() { if (match(Token::Type::kSampler)) - return module_.create(ast::type::SamplerKind::kSampler); + return module_.create(type::SamplerKind::kSampler); if (match(Token::Type::kComparisonSampler)) - return module_.create( - ast::type::SamplerKind::kComparisonSampler); + return module_.create(type::SamplerKind::kComparisonSampler); return Failure::kNoMatch; } @@ -584,36 +582,36 @@ Maybe ParserImpl::sampler_type() { // | TEXTURE_SAMPLED_3D // | TEXTURE_SAMPLED_CUBE // | TEXTURE_SAMPLED_CUBE_ARRAY -Maybe ParserImpl::sampled_texture_type() { +Maybe ParserImpl::sampled_texture_type() { if (match(Token::Type::kTextureSampled1d)) - return ast::type::TextureDimension::k1d; + return type::TextureDimension::k1d; if (match(Token::Type::kTextureSampled1dArray)) - return ast::type::TextureDimension::k1dArray; + return type::TextureDimension::k1dArray; if (match(Token::Type::kTextureSampled2d)) - return ast::type::TextureDimension::k2d; + return type::TextureDimension::k2d; if (match(Token::Type::kTextureSampled2dArray)) - return ast::type::TextureDimension::k2dArray; + return type::TextureDimension::k2dArray; if (match(Token::Type::kTextureSampled3d)) - return ast::type::TextureDimension::k3d; + return type::TextureDimension::k3d; if (match(Token::Type::kTextureSampledCube)) - return ast::type::TextureDimension::kCube; + return type::TextureDimension::kCube; if (match(Token::Type::kTextureSampledCubeArray)) - return ast::type::TextureDimension::kCubeArray; + return type::TextureDimension::kCubeArray; return Failure::kNoMatch; } // multisampled_texture_type // : TEXTURE_MULTISAMPLED_2D -Maybe ParserImpl::multisampled_texture_type() { +Maybe ParserImpl::multisampled_texture_type() { if (match(Token::Type::kTextureMultisampled2d)) - return ast::type::TextureDimension::k2d; + return type::TextureDimension::k2d; return Failure::kNoMatch; } @@ -624,17 +622,17 @@ Maybe ParserImpl::multisampled_texture_type() { // | TEXTURE_STORAGE_2D // | TEXTURE_STORAGE_2D_ARRAY // | TEXTURE_STORAGE_3D -Maybe ParserImpl::storage_texture_type() { +Maybe ParserImpl::storage_texture_type() { if (match(Token::Type::kTextureStorage1d)) - return ast::type::TextureDimension::k1d; + return type::TextureDimension::k1d; if (match(Token::Type::kTextureStorage1dArray)) - return ast::type::TextureDimension::k1dArray; + return type::TextureDimension::k1dArray; if (match(Token::Type::kTextureStorage2d)) - return ast::type::TextureDimension::k2d; + return type::TextureDimension::k2d; if (match(Token::Type::kTextureStorage2dArray)) - return ast::type::TextureDimension::k2dArray; + return type::TextureDimension::k2dArray; if (match(Token::Type::kTextureStorage3d)) - return ast::type::TextureDimension::k3d; + return type::TextureDimension::k3d; return Failure::kNoMatch; } @@ -661,54 +659,49 @@ Maybe ParserImpl::storage_texture_type() { // | TEXTURE_STORAGE_WO_2D // | TEXTURE_STORAGE_WO_2D_ARRAY // | TEXTURE_STORAGE_WO_3D -Maybe> +Maybe> ParserImpl::storage_texture_type_access_control() { - using Ret = std::pair; + using Ret = std::pair; if (match(Token::Type::kTextureStorageReadonly1d)) { - return Ret{ast::type::TextureDimension::k1d, ast::AccessControl::kReadOnly}; + return Ret{type::TextureDimension::k1d, ast::AccessControl::kReadOnly}; } if (match(Token::Type::kTextureStorageReadonly1dArray)) { - return Ret{ast::type::TextureDimension::k1dArray, - ast::AccessControl::kReadOnly}; + return Ret{type::TextureDimension::k1dArray, ast::AccessControl::kReadOnly}; } if (match(Token::Type::kTextureStorageReadonly2d)) { - return Ret{ast::type::TextureDimension::k2d, ast::AccessControl::kReadOnly}; + return Ret{type::TextureDimension::k2d, ast::AccessControl::kReadOnly}; } if (match(Token::Type::kTextureStorageReadonly2dArray)) { - return Ret{ast::type::TextureDimension::k2dArray, - ast::AccessControl::kReadOnly}; + return Ret{type::TextureDimension::k2dArray, ast::AccessControl::kReadOnly}; } if (match(Token::Type::kTextureStorageReadonly3d)) { - return Ret{ast::type::TextureDimension::k3d, ast::AccessControl::kReadOnly}; + return Ret{type::TextureDimension::k3d, ast::AccessControl::kReadOnly}; } if (match(Token::Type::kTextureStorageWriteonly1d)) { - return Ret{ast::type::TextureDimension::k1d, - ast::AccessControl::kWriteOnly}; + return Ret{type::TextureDimension::k1d, ast::AccessControl::kWriteOnly}; } if (match(Token::Type::kTextureStorageWriteonly1dArray)) { - return Ret{ast::type::TextureDimension::k1dArray, + return Ret{type::TextureDimension::k1dArray, ast::AccessControl::kWriteOnly}; } if (match(Token::Type::kTextureStorageWriteonly2d)) { - return Ret{ast::type::TextureDimension::k2d, - ast::AccessControl::kWriteOnly}; + return Ret{type::TextureDimension::k2d, ast::AccessControl::kWriteOnly}; } if (match(Token::Type::kTextureStorageWriteonly2dArray)) { - return Ret{ast::type::TextureDimension::k2dArray, + return Ret{type::TextureDimension::k2dArray, ast::AccessControl::kWriteOnly}; } if (match(Token::Type::kTextureStorageWriteonly3d)) { - return Ret{ast::type::TextureDimension::k3d, - ast::AccessControl::kWriteOnly}; + return Ret{type::TextureDimension::k3d, ast::AccessControl::kWriteOnly}; } return Failure::kNoMatch; @@ -719,22 +712,19 @@ ParserImpl::storage_texture_type_access_control() { // | TEXTURE_DEPTH_2D_ARRAY // | TEXTURE_DEPTH_CUBE // | TEXTURE_DEPTH_CUBE_ARRAY -Maybe ParserImpl::depth_texture_type() { +Maybe ParserImpl::depth_texture_type() { if (match(Token::Type::kTextureDepth2d)) - return module_.create( - ast::type::TextureDimension::k2d); + return module_.create(type::TextureDimension::k2d); if (match(Token::Type::kTextureDepth2dArray)) - return module_.create( - ast::type::TextureDimension::k2dArray); + return module_.create(type::TextureDimension::k2dArray); if (match(Token::Type::kTextureDepthCube)) - return module_.create( - ast::type::TextureDimension::kCube); + return module_.create(type::TextureDimension::kCube); if (match(Token::Type::kTextureDepthCubeArray)) - return module_.create( - ast::type::TextureDimension::kCubeArray); + return module_.create( + type::TextureDimension::kCubeArray); return Failure::kNoMatch; } @@ -775,112 +765,112 @@ Maybe ParserImpl::depth_texture_type() { // | RGBA32UINT // | RGBA32SINT // | RGBA32FLOAT -Expect ParserImpl::expect_image_storage_type( +Expect ParserImpl::expect_image_storage_type( const std::string& use) { if (match(Token::Type::kFormatR8Unorm)) - return ast::type::ImageFormat::kR8Unorm; + return type::ImageFormat::kR8Unorm; if (match(Token::Type::kFormatR8Snorm)) - return ast::type::ImageFormat::kR8Snorm; + return type::ImageFormat::kR8Snorm; if (match(Token::Type::kFormatR8Uint)) - return ast::type::ImageFormat::kR8Uint; + return type::ImageFormat::kR8Uint; if (match(Token::Type::kFormatR8Sint)) - return ast::type::ImageFormat::kR8Sint; + return type::ImageFormat::kR8Sint; if (match(Token::Type::kFormatR16Uint)) - return ast::type::ImageFormat::kR16Uint; + return type::ImageFormat::kR16Uint; if (match(Token::Type::kFormatR16Sint)) - return ast::type::ImageFormat::kR16Sint; + return type::ImageFormat::kR16Sint; if (match(Token::Type::kFormatR16Float)) - return ast::type::ImageFormat::kR16Float; + return type::ImageFormat::kR16Float; if (match(Token::Type::kFormatRg8Unorm)) - return ast::type::ImageFormat::kRg8Unorm; + return type::ImageFormat::kRg8Unorm; if (match(Token::Type::kFormatRg8Snorm)) - return ast::type::ImageFormat::kRg8Snorm; + return type::ImageFormat::kRg8Snorm; if (match(Token::Type::kFormatRg8Uint)) - return ast::type::ImageFormat::kRg8Uint; + return type::ImageFormat::kRg8Uint; if (match(Token::Type::kFormatRg8Sint)) - return ast::type::ImageFormat::kRg8Sint; + return type::ImageFormat::kRg8Sint; if (match(Token::Type::kFormatR32Uint)) - return ast::type::ImageFormat::kR32Uint; + return type::ImageFormat::kR32Uint; if (match(Token::Type::kFormatR32Sint)) - return ast::type::ImageFormat::kR32Sint; + return type::ImageFormat::kR32Sint; if (match(Token::Type::kFormatR32Float)) - return ast::type::ImageFormat::kR32Float; + return type::ImageFormat::kR32Float; if (match(Token::Type::kFormatRg16Uint)) - return ast::type::ImageFormat::kRg16Uint; + return type::ImageFormat::kRg16Uint; if (match(Token::Type::kFormatRg16Sint)) - return ast::type::ImageFormat::kRg16Sint; + return type::ImageFormat::kRg16Sint; if (match(Token::Type::kFormatRg16Float)) - return ast::type::ImageFormat::kRg16Float; + return type::ImageFormat::kRg16Float; if (match(Token::Type::kFormatRgba8Unorm)) - return ast::type::ImageFormat::kRgba8Unorm; + return type::ImageFormat::kRgba8Unorm; if (match(Token::Type::kFormatRgba8UnormSrgb)) - return ast::type::ImageFormat::kRgba8UnormSrgb; + return type::ImageFormat::kRgba8UnormSrgb; if (match(Token::Type::kFormatRgba8Snorm)) - return ast::type::ImageFormat::kRgba8Snorm; + return type::ImageFormat::kRgba8Snorm; if (match(Token::Type::kFormatRgba8Uint)) - return ast::type::ImageFormat::kRgba8Uint; + return type::ImageFormat::kRgba8Uint; if (match(Token::Type::kFormatRgba8Sint)) - return ast::type::ImageFormat::kRgba8Sint; + return type::ImageFormat::kRgba8Sint; if (match(Token::Type::kFormatBgra8Unorm)) - return ast::type::ImageFormat::kBgra8Unorm; + return type::ImageFormat::kBgra8Unorm; if (match(Token::Type::kFormatBgra8UnormSrgb)) - return ast::type::ImageFormat::kBgra8UnormSrgb; + return type::ImageFormat::kBgra8UnormSrgb; if (match(Token::Type::kFormatRgb10A2Unorm)) - return ast::type::ImageFormat::kRgb10A2Unorm; + return type::ImageFormat::kRgb10A2Unorm; if (match(Token::Type::kFormatRg11B10Float)) - return ast::type::ImageFormat::kRg11B10Float; + return type::ImageFormat::kRg11B10Float; if (match(Token::Type::kFormatRg32Uint)) - return ast::type::ImageFormat::kRg32Uint; + return type::ImageFormat::kRg32Uint; if (match(Token::Type::kFormatRg32Sint)) - return ast::type::ImageFormat::kRg32Sint; + return type::ImageFormat::kRg32Sint; if (match(Token::Type::kFormatRg32Float)) - return ast::type::ImageFormat::kRg32Float; + return type::ImageFormat::kRg32Float; if (match(Token::Type::kFormatRgba16Uint)) - return ast::type::ImageFormat::kRgba16Uint; + return type::ImageFormat::kRgba16Uint; if (match(Token::Type::kFormatRgba16Sint)) - return ast::type::ImageFormat::kRgba16Sint; + return type::ImageFormat::kRgba16Sint; if (match(Token::Type::kFormatRgba16Float)) - return ast::type::ImageFormat::kRgba16Float; + return type::ImageFormat::kRgba16Float; if (match(Token::Type::kFormatRgba32Uint)) - return ast::type::ImageFormat::kRgba32Uint; + return type::ImageFormat::kRgba32Uint; if (match(Token::Type::kFormatRgba32Sint)) - return ast::type::ImageFormat::kRgba32Sint; + return type::ImageFormat::kRgba32Sint; if (match(Token::Type::kFormatRgba32Float)) - return ast::type::ImageFormat::kRgba32Float; + return type::ImageFormat::kRgba32Float; return add_error(peek().source(), "invalid format", use); } @@ -919,7 +909,7 @@ Expect ParserImpl::expect_variable_ident_decl( for (auto* deco : access_decos) { // If we have an access control decoration then we take it and wrap our // type up with that decoration - ty = module_.create( + ty = module_.create( deco->As()->value(), ty); } @@ -959,7 +949,7 @@ Maybe ParserImpl::variable_storage_decoration() { // type_alias // : TYPE IDENT EQUAL type_decl -Maybe ParserImpl::type_alias() { +Maybe ParserImpl::type_alias() { auto t = peek(); if (!t.IsType()) return Failure::kNoMatch; @@ -981,8 +971,8 @@ Maybe ParserImpl::type_alias() { if (!type.matched) return add_error(peek(), "invalid type alias"); - auto* alias = module_.create( - module_.RegisterSymbol(name.value), type.value); + auto* alias = module_.create(module_.RegisterSymbol(name.value), + type.value); register_constructed(name.value, alias); return alias; @@ -1012,7 +1002,7 @@ Maybe ParserImpl::type_alias() { // | MAT4x3 LESS_THAN type_decl GREATER_THAN // | MAT4x4 LESS_THAN type_decl GREATER_THAN // | texture_sampler_types -Maybe ParserImpl::type_decl() { +Maybe ParserImpl::type_decl() { auto decos = decoration_list(); if (decos.errored) return Failure::kErrored; @@ -1029,7 +1019,7 @@ Maybe ParserImpl::type_decl() { return type.value; } -Maybe ParserImpl::type_decl(ast::DecorationList& decos) { +Maybe ParserImpl::type_decl(ast::DecorationList& decos) { auto t = peek(); if (match(Token::Type::kIdentifier)) { auto* ty = get_constructed(t.to_str()); @@ -1040,16 +1030,16 @@ Maybe ParserImpl::type_decl(ast::DecorationList& decos) { } if (match(Token::Type::kBool)) - return module_.create(); + return module_.create(); if (match(Token::Type::kF32)) - return module_.create(); + return module_.create(); if (match(Token::Type::kI32)) - return module_.create(); + return module_.create(); if (match(Token::Type::kU32)) - return module_.create(); + return module_.create(); if (t.IsVec2() || t.IsVec3() || t.IsVec4()) { next(); // Consume the peek @@ -1083,7 +1073,7 @@ Maybe ParserImpl::type_decl(ast::DecorationList& decos) { return Failure::kNoMatch; } -Expect ParserImpl::expect_type(const std::string& use) { +Expect ParserImpl::expect_type(const std::string& use) { auto type = type_decl(); if (type.errored) return Failure::kErrored; @@ -1092,10 +1082,10 @@ Expect ParserImpl::expect_type(const std::string& use) { return type.value; } -Expect ParserImpl::expect_type_decl_pointer() { +Expect ParserImpl::expect_type_decl_pointer() { const char* use = "ptr declaration"; - return expect_lt_gt_block(use, [&]() -> Expect { + return expect_lt_gt_block(use, [&]() -> Expect { auto sc = expect_storage_class(use); if (sc.errored) return Failure::kErrored; @@ -1107,11 +1097,11 @@ Expect ParserImpl::expect_type_decl_pointer() { if (subtype.errored) return Failure::kErrored; - return module_.create(subtype.value, sc.value); + return module_.create(subtype.value, sc.value); }); } -Expect ParserImpl::expect_type_decl_vector(Token t) { +Expect ParserImpl::expect_type_decl_vector(Token t) { uint32_t count = 2; if (t.IsVec3()) count = 3; @@ -1124,14 +1114,14 @@ Expect ParserImpl::expect_type_decl_vector(Token t) { if (subtype.errored) return Failure::kErrored; - return module_.create(subtype.value, count); + return module_.create(subtype.value, count); } -Expect ParserImpl::expect_type_decl_array( +Expect ParserImpl::expect_type_decl_array( ast::ArrayDecorationList decos) { const char* use = "array declaration"; - return expect_lt_gt_block(use, [&]() -> Expect { + return expect_lt_gt_block(use, [&]() -> Expect { auto subtype = expect_type(use); if (subtype.errored) return Failure::kErrored; @@ -1144,11 +1134,11 @@ Expect ParserImpl::expect_type_decl_array( size = val.value; } - return create(subtype.value, size, std::move(decos)); + return create(subtype.value, size, std::move(decos)); }); } -Expect ParserImpl::expect_type_decl_matrix(Token t) { +Expect ParserImpl::expect_type_decl_matrix(Token t) { uint32_t rows = 2; uint32_t columns = 2; if (t.IsMat3x2() || t.IsMat3x3() || t.IsMat3x4()) { @@ -1168,7 +1158,7 @@ Expect ParserImpl::expect_type_decl_matrix(Token t) { if (subtype.errored) return Failure::kErrored; - return module_.create(subtype.value, rows, columns); + return module_.create(subtype.value, rows, columns); } // storage_class @@ -1215,7 +1205,7 @@ Expect ParserImpl::expect_storage_class( // struct_decl // : struct_decoration_decl* STRUCT IDENT struct_body_decl -Maybe> ParserImpl::struct_decl( +Maybe> ParserImpl::struct_decl( ast::DecorationList& decos) { auto t = peek(); auto source = t.source(); @@ -1235,7 +1225,7 @@ Maybe> ParserImpl::struct_decl( if (struct_decos.errored) return Failure::kErrored; - return std::make_unique( + return std::make_unique( module_.RegisterSymbol(name.value), create(source, std::move(body.value), std::move(struct_decos.value))); @@ -1335,9 +1325,9 @@ Maybe ParserImpl::function_decl(ast::DecorationList& decos) { // function_type_decl // : type_decl // | VOID -Maybe ParserImpl::function_type_decl() { +Maybe ParserImpl::function_type_decl() { if (match(Token::Type::kVoid)) - return module_.create(); + return module_.create(); return type_decl(); } @@ -2749,19 +2739,19 @@ Maybe ParserImpl::assignment_stmt() { Maybe ParserImpl::const_literal() { auto t = peek(); if (match(Token::Type::kTrue)) { - auto* type = module_.create(); + auto* type = module_.create(); return create(Source{}, type, true); } if (match(Token::Type::kFalse)) { - auto* type = module_.create(); + auto* type = module_.create(); return create(Source{}, type, false); } if (match(Token::Type::kSintLiteral)) { - auto* type = module_.create(); + auto* type = module_.create(); return create(Source{}, type, t.to_i32()); } if (match(Token::Type::kUintLiteral)) { - auto* type = module_.create(); + auto* type = module_.create(); return create(Source{}, type, t.to_u32()); } if (match(Token::Type::kFloatLiteral)) { @@ -2770,7 +2760,7 @@ Maybe ParserImpl::const_literal() { next(); // Consume 'f' add_error(p.source(), "float literals must not be suffixed with 'f'"); } - auto* type = module_.create(); + auto* type = module_.create(); return create(Source{}, type, t.to_f32()); } return Failure::kNoMatch; diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index 385e89041c..d4d6a4d7b7 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -48,10 +48,6 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decoration.h" @@ -59,6 +55,10 @@ #include "src/diagnostic/formatter.h" #include "src/reader/wgsl/parser_impl_detail.h" #include "src/reader/wgsl/token.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/type.h" namespace tint { namespace reader { @@ -222,7 +222,7 @@ class ParserImpl { /// variable_ident_decl(). struct TypedIdentifier { /// Parsed type. - ast::type::Type* type = nullptr; + type::Type* type = nullptr; /// Parsed identifier. std::string name; /// Source to the identifier. @@ -244,7 +244,7 @@ class ParserImpl { FunctionHeader(Source src, std::string n, ast::VariableList p, - ast::type::Type* ret_ty); + type::Type* ret_ty); /// Destructor ~FunctionHeader(); /// Assignment operator @@ -259,7 +259,7 @@ class ParserImpl { /// Function parameters ast::VariableList params; /// Function return type - ast::type::Type* return_type; + type::Type* return_type; }; /// VarDeclInfo contains the parsed information for variable declaration. @@ -271,7 +271,7 @@ class ParserImpl { /// Variable storage class ast::StorageClass storage_class; /// Variable type - ast::type::Type* type; + type::Type* type; }; /// Creates a new parser using the given file @@ -348,11 +348,11 @@ class ParserImpl { /// Registers a constructed type into the parser /// @param name the constructed name /// @param type the constructed type - void register_constructed(const std::string& name, ast::type::Type* type); + void register_constructed(const std::string& name, type::Type* type); /// Retrieves a constructed type /// @param name The name to lookup /// @returns the constructed type for `name` or `nullptr` if not found - ast::type::Type* get_constructed(const std::string& name); + type::Type* get_constructed(const std::string& name); /// Parses the `translation_unit` grammar element void translation_unit(); @@ -380,15 +380,15 @@ class ParserImpl { Maybe variable_storage_decoration(); /// Parses a `type_alias` grammar element /// @returns the type alias or nullptr on error - Maybe type_alias(); + Maybe type_alias(); /// Parses a `type_decl` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe type_decl(); + Maybe type_decl(); /// Parses a `type_decl` grammar element with the given pre-parsed /// decorations. /// @param decos the list of decorations for the type. /// @returns the parsed Type or nullptr if none matched. - Maybe type_decl(ast::DecorationList& decos); + Maybe type_decl(ast::DecorationList& decos); /// Parses a `storage_class` grammar element, erroring on parse failure. /// @param use a description of what was being parsed if an error was raised. /// @returns the storage class or StorageClass::kNone if none matched @@ -397,8 +397,7 @@ class ParserImpl { /// `struct_decoration_decl*` provided as `decos`. /// @returns the struct type or nullptr on error /// @param decos the list of decorations for the struct declaration. - Maybe> struct_decl( - ast::DecorationList& decos); + Maybe> struct_decl(ast::DecorationList& decos); /// Parses a `struct_body_decl` grammar element, erroring on parse failure. /// @returns the struct members Expect expect_struct_body_decl(); @@ -415,37 +414,36 @@ class ParserImpl { Maybe function_decl(ast::DecorationList& decos); /// Parses a `texture_sampler_types` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe texture_sampler_types(); + Maybe texture_sampler_types(); /// Parses a `sampler_type` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe sampler_type(); + Maybe sampler_type(); /// Parses a `multisampled_texture_type` grammar element /// @returns returns the multisample texture dimension or kNone if none /// matched. - Maybe multisampled_texture_type(); + Maybe multisampled_texture_type(); /// Parses a `sampled_texture_type` grammar element /// @returns returns the sample texture dimension or kNone if none matched. - Maybe sampled_texture_type(); + Maybe sampled_texture_type(); /// Parses a `storage_texture_type` grammar element /// @returns returns the storage texture dimension. /// Returns kNone if none matched. - Maybe storage_texture_type(); + Maybe storage_texture_type(); /// Parses a deprecated `storage_texture_type` grammar element /// @returns returns the storage texture dimension and the storage access. /// Returns kNone and kRead if none matched. - Maybe> + Maybe> storage_texture_type_access_control(); /// Parses a `depth_texture_type` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe depth_texture_type(); + Maybe depth_texture_type(); /// Parses a `image_storage_type` grammar element /// @param use a description of what was being parsed if an error was raised /// @returns returns the image format or kNone if none matched. - Expect expect_image_storage_type( - const std::string& use); + Expect expect_image_storage_type(const std::string& use); /// Parses a `function_type_decl` grammar element /// @returns the parsed type or nullptr otherwise - Maybe function_type_decl(); + Maybe function_type_decl(); /// Parses a `function_header` grammar element /// @returns the parsed function header Maybe function_header(); @@ -811,16 +809,15 @@ class ParserImpl { /// Used to ensure that all decorations are consumed. bool expect_decorations_consumed(const ast::DecorationList& list); - Expect expect_type_decl_pointer(); - Expect expect_type_decl_vector(Token t); - Expect expect_type_decl_array( - ast::ArrayDecorationList decos); - Expect expect_type_decl_matrix(Token t); + Expect expect_type_decl_pointer(); + Expect expect_type_decl_vector(Token t); + Expect expect_type_decl_array(ast::ArrayDecorationList decos); + Expect expect_type_decl_matrix(Token t); Expect expect_const_expr_internal( uint32_t depth); - Expect expect_type(const std::string& use); + Expect expect_type(const std::string& use); Maybe non_block_statement(); Maybe for_header_initializer(); @@ -841,7 +838,7 @@ class ParserImpl { bool synchronized_ = true; std::vector sync_tokens_; int silence_errors_ = 0; - std::unordered_map registered_constructs_; + std::unordered_map registered_constructs_; ast::Module module_; size_t max_errors_ = 25; }; diff --git a/src/reader/wgsl/parser_impl_const_expr_test.cc b/src/reader/wgsl/parser_impl_const_expr_test.cc index 8dd60682bb..8930fd2f9d 100644 --- a/src/reader/wgsl/parser_impl_const_expr_test.cc +++ b/src/reader/wgsl/parser_impl_const_expr_test.cc @@ -16,10 +16,10 @@ #include "src/ast/bool_literal.h" #include "src/ast/float_literal.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/vector_type.h" namespace tint { namespace reader { @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) { ASSERT_TRUE(e->Is()); auto* t = e->As(); - ASSERT_TRUE(t->type()->Is()); - EXPECT_EQ(t->type()->As()->size(), 2u); + ASSERT_TRUE(t->type()->Is()); + EXPECT_EQ(t->type()->As()->size(), 2u); ASSERT_EQ(t->values().size(), 2u); auto& v = t->values(); diff --git a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc index 2e12319014..05da40148d 100644 --- a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/depth_texture_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/depth_texture_type.h" namespace tint { namespace reader { @@ -36,10 +36,9 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -49,10 +48,9 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2dArray); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -62,10 +60,9 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::kCube); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); } @@ -75,10 +72,9 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::kCubeArray); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc index 519e40848e..17b9fd1d70 100644 --- a/src/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_decl_test.cc @@ -14,11 +14,11 @@ #include "gtest/gtest.h" #include "src/ast/function.h" -#include "src/ast/type/type.h" -#include "src/ast/type/void_type.h" #include "src/ast/workgroup_decoration.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/type.h" +#include "src/type/void_type.h" namespace tint { namespace reader { @@ -39,14 +39,14 @@ TEST_F(ParserImplTest, FunctionDecl) { EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 2u); EXPECT_EQ(f->params()[0]->symbol(), p->get_module().RegisterSymbol("a")); EXPECT_EQ(f->params()[1]->symbol(), p->get_module().RegisterSymbol("b")); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); auto* body = f->body(); ASSERT_EQ(body->size(), 1u); @@ -67,10 +67,10 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 0u); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); auto& decorations = f->decorations(); ASSERT_EQ(decorations.size(), 1u); @@ -105,10 +105,10 @@ fn main() -> void { return; })"); EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 0u); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); auto& decorations = f->decorations(); ASSERT_EQ(decorations.size(), 2u); @@ -150,10 +150,10 @@ fn main() -> void { return; })"); EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 0u); ASSERT_NE(f->return_type(), nullptr); - EXPECT_TRUE(f->return_type()->Is()); + EXPECT_TRUE(f->return_type()->Is()); auto& decos = f->decorations(); ASSERT_EQ(decos.size(), 2u); diff --git a/src/reader/wgsl/parser_impl_function_header_test.cc b/src/reader/wgsl/parser_impl_function_header_test.cc index 529de06e1f..1a77313eb3 100644 --- a/src/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/reader/wgsl/parser_impl_function_header_test.cc @@ -14,10 +14,10 @@ #include "gtest/gtest.h" #include "src/ast/function.h" -#include "src/ast/type/type.h" -#include "src/ast/type/void_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/type.h" +#include "src/type/void_type.h" namespace tint { namespace reader { @@ -35,7 +35,7 @@ TEST_F(ParserImplTest, FunctionHeader) { ASSERT_EQ(f->params.size(), 2u); EXPECT_EQ(f->params[0]->symbol(), p->get_module().RegisterSymbol("a")); EXPECT_EQ(f->params[1]->symbol(), p->get_module().RegisterSymbol("b")); - EXPECT_TRUE(f->return_type->Is()); + EXPECT_TRUE(f->return_type->Is()); } TEST_F(ParserImplTest, FunctionHeader_MissingIdent) { diff --git a/src/reader/wgsl/parser_impl_function_type_decl_test.cc b/src/reader/wgsl/parser_impl_function_type_decl_test.cc index b4160e5e48..f3f16bf464 100644 --- a/src/reader/wgsl/parser_impl_function_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_type_decl_test.cc @@ -15,11 +15,11 @@ #include #include "gtest/gtest.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { namespace reader { @@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Void) { auto p = parser("void"); auto& mod = p->get_module(); - auto* v = mod.create(); + auto* v = mod.create(); auto e = p->function_type_decl(); EXPECT_TRUE(e.matched); @@ -43,8 +43,8 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Type) { auto p = parser("vec2"); auto& mod = p->get_module(); - auto* f32 = mod.create(); - auto* vec2 = mod.create(f32, 2); + auto* f32 = mod.create(); + auto* vec2 = mod.create(f32, 2); auto e = p->function_type_decl(); EXPECT_TRUE(e.matched); diff --git a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc index 89864db510..149b6d91e1 100644 --- a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -13,11 +13,11 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/f32_type.h" namespace tint { namespace reader { @@ -35,7 +35,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) { EXPECT_TRUE(e->is_const()); EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->source().range.begin.line, 1u); EXPECT_EQ(e->source().range.begin.column, 7u); diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index 0aee4bff65..7fac54c3e5 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -13,10 +13,10 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/struct_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/array_type.h" +#include "src/type/struct_type.h" namespace tint { namespace reader { @@ -88,10 +88,10 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) { auto& m = p->get_module(); ASSERT_EQ(m.constructed_types().size(), 1u); - ASSERT_TRUE(m.constructed_types()[0]->Is()); - EXPECT_EQ(m.SymbolToName( - m.constructed_types()[0]->As()->symbol()), - "A"); + ASSERT_TRUE(m.constructed_types()[0]->Is()); + EXPECT_EQ( + m.SymbolToName(m.constructed_types()[0]->As()->symbol()), + "A"); } TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) { @@ -105,12 +105,12 @@ type B = A;)"); auto& m = p->get_module(); ASSERT_EQ(m.constructed_types().size(), 2u); - ASSERT_TRUE(m.constructed_types()[0]->Is()); - auto* str = m.constructed_types()[0]->As(); + ASSERT_TRUE(m.constructed_types()[0]->Is()); + auto* str = m.constructed_types()[0]->As(); EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); - ASSERT_TRUE(m.constructed_types()[1]->Is()); - auto* alias = m.constructed_types()[1]->As(); + ASSERT_TRUE(m.constructed_types()[1]->Is()); + auto* alias = m.constructed_types()[1]->As(); EXPECT_EQ(alias->symbol(), p->get_module().RegisterSymbol("B")); EXPECT_EQ(alias->type(), str); } @@ -166,9 +166,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) { auto* t = m.constructed_types()[0]; ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* str = t->As(); + auto* str = t->As(); EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 2u); } @@ -185,16 +185,16 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { auto* t = m.constructed_types()[0]; ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* str = t->As(); + auto* str = t->As(); EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_FALSE(str->IsBlockDecorated()); const auto* ty = str->impl()->members()[0]->type(); - ASSERT_TRUE(ty->Is()); - const auto* arr = ty->As(); + ASSERT_TRUE(ty->Is()); + const auto* arr = ty->As(); EXPECT_TRUE(arr->has_array_stride()); EXPECT_EQ(arr->array_stride(), 4u); } @@ -209,9 +209,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { auto* t = m.constructed_types()[0]; ASSERT_NE(t, nullptr); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* str = t->As(); + auto* str = t->As(); EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_TRUE(str->IsBlockDecorated()); diff --git a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc index f17cecab2a..84c392d1b2 100644 --- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -14,11 +14,11 @@ #include "gtest/gtest.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/f32_type.h" namespace tint { namespace reader { @@ -37,7 +37,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) { ASSERT_NE(e.value, nullptr); EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->source().range.begin.line, 1u); @@ -60,7 +60,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { ASSERT_NE(e.value, nullptr); EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->source().range.begin.line, 1u); @@ -86,7 +86,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->source().range.begin.line, 1u); @@ -116,7 +116,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) { EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); ASSERT_NE(e->type(), nullptr); - EXPECT_TRUE(e->type()->Is()); + EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->source().range.begin.line, 1u); diff --git a/src/reader/wgsl/parser_impl_image_storage_type_test.cc b/src/reader/wgsl/parser_impl_image_storage_type_test.cc index 64462f791d..7f125499ab 100644 --- a/src/reader/wgsl/parser_impl_image_storage_type_test.cc +++ b/src/reader/wgsl/parser_impl_image_storage_type_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/texture_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/texture_type.h" namespace tint { namespace reader { @@ -34,7 +34,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Unorm) { auto p = parser("r8unorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR8Unorm); + EXPECT_EQ(t.value, type::ImageFormat::kR8Unorm); EXPECT_FALSE(p->has_error()); } @@ -42,7 +42,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Snorm) { auto p = parser("r8snorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR8Snorm); + EXPECT_EQ(t.value, type::ImageFormat::kR8Snorm); EXPECT_FALSE(p->has_error()); } @@ -50,7 +50,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Uint) { auto p = parser("r8uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR8Uint); + EXPECT_EQ(t.value, type::ImageFormat::kR8Uint); EXPECT_FALSE(p->has_error()); } @@ -58,7 +58,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Sint) { auto p = parser("r8sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR8Sint); + EXPECT_EQ(t.value, type::ImageFormat::kR8Sint); EXPECT_FALSE(p->has_error()); } @@ -66,7 +66,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Uint) { auto p = parser("r16uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR16Uint); + EXPECT_EQ(t.value, type::ImageFormat::kR16Uint); EXPECT_FALSE(p->has_error()); } @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Sint) { auto p = parser("r16sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR16Sint); + EXPECT_EQ(t.value, type::ImageFormat::kR16Sint); EXPECT_FALSE(p->has_error()); } @@ -82,7 +82,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Float) { auto p = parser("r16float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR16Float); + EXPECT_EQ(t.value, type::ImageFormat::kR16Float); EXPECT_FALSE(p->has_error()); } @@ -90,7 +90,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Unorm) { auto p = parser("rg8unorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg8Unorm); + EXPECT_EQ(t.value, type::ImageFormat::kRg8Unorm); EXPECT_FALSE(p->has_error()); } @@ -98,7 +98,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Snorm) { auto p = parser("rg8snorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg8Snorm); + EXPECT_EQ(t.value, type::ImageFormat::kRg8Snorm); EXPECT_FALSE(p->has_error()); } @@ -106,7 +106,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Uint) { auto p = parser("rg8uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg8Uint); + EXPECT_EQ(t.value, type::ImageFormat::kRg8Uint); EXPECT_FALSE(p->has_error()); } @@ -114,7 +114,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Sint) { auto p = parser("rg8sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg8Sint); + EXPECT_EQ(t.value, type::ImageFormat::kRg8Sint); EXPECT_FALSE(p->has_error()); } @@ -122,7 +122,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Uint) { auto p = parser("r32uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR32Uint); + EXPECT_EQ(t.value, type::ImageFormat::kR32Uint); EXPECT_FALSE(p->has_error()); } @@ -130,7 +130,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Sint) { auto p = parser("r32sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR32Sint); + EXPECT_EQ(t.value, type::ImageFormat::kR32Sint); EXPECT_FALSE(p->has_error()); } @@ -138,7 +138,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Float) { auto p = parser("r32float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kR32Float); + EXPECT_EQ(t.value, type::ImageFormat::kR32Float); EXPECT_FALSE(p->has_error()); } @@ -146,7 +146,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Uint) { auto p = parser("rg16uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg16Uint); + EXPECT_EQ(t.value, type::ImageFormat::kRg16Uint); EXPECT_FALSE(p->has_error()); } @@ -154,7 +154,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Sint) { auto p = parser("rg16sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg16Sint); + EXPECT_EQ(t.value, type::ImageFormat::kRg16Sint); EXPECT_FALSE(p->has_error()); } @@ -162,7 +162,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Float) { auto p = parser("rg16float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg16Float); + EXPECT_EQ(t.value, type::ImageFormat::kRg16Float); EXPECT_FALSE(p->has_error()); } @@ -170,7 +170,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Unorm) { auto p = parser("rgba8unorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba8Unorm); + EXPECT_EQ(t.value, type::ImageFormat::kRgba8Unorm); EXPECT_FALSE(p->has_error()); } @@ -178,7 +178,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8UnormSrgb) { auto p = parser("rgba8unorm_srgb"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba8UnormSrgb); + EXPECT_EQ(t.value, type::ImageFormat::kRgba8UnormSrgb); EXPECT_FALSE(p->has_error()); } @@ -186,7 +186,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Snorm) { auto p = parser("rgba8snorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba8Snorm); + EXPECT_EQ(t.value, type::ImageFormat::kRgba8Snorm); EXPECT_FALSE(p->has_error()); } @@ -194,7 +194,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Uint) { auto p = parser("rgba8uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba8Uint); + EXPECT_EQ(t.value, type::ImageFormat::kRgba8Uint); EXPECT_FALSE(p->has_error()); } @@ -202,7 +202,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Sint) { auto p = parser("rgba8sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba8Sint); + EXPECT_EQ(t.value, type::ImageFormat::kRgba8Sint); EXPECT_FALSE(p->has_error()); } @@ -210,7 +210,7 @@ TEST_F(ParserImplTest, ImageStorageType_Bgra8Unorm) { auto p = parser("bgra8unorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kBgra8Unorm); + EXPECT_EQ(t.value, type::ImageFormat::kBgra8Unorm); EXPECT_FALSE(p->has_error()); } @@ -218,7 +218,7 @@ TEST_F(ParserImplTest, ImageStorageType_Bgra8UnormSrgb) { auto p = parser("bgra8unorm_srgb"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kBgra8UnormSrgb); + EXPECT_EQ(t.value, type::ImageFormat::kBgra8UnormSrgb); EXPECT_FALSE(p->has_error()); } @@ -226,7 +226,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgb10A2Unorm) { auto p = parser("rgb10a2unorm"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgb10A2Unorm); + EXPECT_EQ(t.value, type::ImageFormat::kRgb10A2Unorm); EXPECT_FALSE(p->has_error()); } @@ -234,7 +234,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg11B10Float) { auto p = parser("rg11b10float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg11B10Float); + EXPECT_EQ(t.value, type::ImageFormat::kRg11B10Float); EXPECT_FALSE(p->has_error()); } @@ -242,7 +242,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Uint) { auto p = parser("rg32uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg32Uint); + EXPECT_EQ(t.value, type::ImageFormat::kRg32Uint); EXPECT_FALSE(p->has_error()); } @@ -250,7 +250,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Sint) { auto p = parser("rg32sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg32Sint); + EXPECT_EQ(t.value, type::ImageFormat::kRg32Sint); EXPECT_FALSE(p->has_error()); } @@ -258,7 +258,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Float) { auto p = parser("rg32float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRg32Float); + EXPECT_EQ(t.value, type::ImageFormat::kRg32Float); EXPECT_FALSE(p->has_error()); } @@ -266,7 +266,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Uint) { auto p = parser("rgba16uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba16Uint); + EXPECT_EQ(t.value, type::ImageFormat::kRgba16Uint); EXPECT_FALSE(p->has_error()); } @@ -274,7 +274,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Sint) { auto p = parser("rgba16sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba16Sint); + EXPECT_EQ(t.value, type::ImageFormat::kRgba16Sint); EXPECT_FALSE(p->has_error()); } @@ -282,7 +282,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Float) { auto p = parser("rgba16float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba16Float); + EXPECT_EQ(t.value, type::ImageFormat::kRgba16Float); EXPECT_FALSE(p->has_error()); } @@ -290,7 +290,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Uint) { auto p = parser("rgba32uint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba32Uint); + EXPECT_EQ(t.value, type::ImageFormat::kRgba32Uint); EXPECT_FALSE(p->has_error()); } @@ -298,7 +298,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Sint) { auto p = parser("rgba32sint"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba32Sint); + EXPECT_EQ(t.value, type::ImageFormat::kRgba32Sint); EXPECT_FALSE(p->has_error()); } @@ -306,7 +306,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Float) { auto p = parser("rgba32float"); auto t = p->expect_image_storage_type("test"); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::ImageFormat::kRgba32Float); + EXPECT_EQ(t.value, type::ImageFormat::kRgba32Float); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_param_list_test.cc b/src/reader/wgsl/parser_impl_param_list_test.cc index 58b3cbd673..a8a9106076 100644 --- a/src/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/reader/wgsl/parser_impl_param_list_test.cc @@ -15,12 +15,12 @@ #include #include "gtest/gtest.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/variable.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace reader { @@ -31,7 +31,7 @@ TEST_F(ParserImplTest, ParamList_Single) { auto p = parser("a : i32"); auto& mod = p->get_module(); - auto* i32 = mod.create(); + auto* i32 = mod.create(); auto e = p->expect_param_list(); ASSERT_FALSE(p->has_error()) << p->error(); @@ -52,9 +52,9 @@ TEST_F(ParserImplTest, ParamList_Multiple) { auto p = parser("a : i32, b: f32, c: vec2"); auto& mod = p->get_module(); - auto* i32 = mod.create(); - auto* f32 = mod.create(); - auto* vec2 = mod.create(f32, 2); + auto* i32 = mod.create(); + auto* f32 = mod.create(); + auto* vec2 = mod.create(f32, 2); auto e = p->expect_param_list(); ASSERT_FALSE(p->has_error()) << p->error(); diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc index a6bdb1b1cc..74ddfc3465 100644 --- a/src/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc @@ -20,12 +20,12 @@ #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" namespace tint { namespace reader { @@ -194,7 +194,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { auto p = parser("f32(1)"); auto& mod = p->get_module(); - auto* f32 = mod.create(); + auto* f32 = mod.create(); auto e = p->primary_expression(); EXPECT_TRUE(e.matched); @@ -216,7 +216,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { auto p = parser("bitcast(1)"); auto& mod = p->get_module(); - auto* f32 = mod.create(); + auto* f32 = mod.create(); auto e = p->primary_expression(); EXPECT_TRUE(e.matched); diff --git a/src/reader/wgsl/parser_impl_sampled_texture_type_test.cc b/src/reader/wgsl/parser_impl_sampled_texture_type_test.cc index deda8b7bd3..fc553e3b8f 100644 --- a/src/reader/wgsl/parser_impl_sampled_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_sampled_texture_type_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/texture_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/texture_type.h" namespace tint { namespace reader { @@ -35,7 +35,7 @@ TEST_F(ParserImplTest, SampledTextureType_1d_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k1d); + EXPECT_EQ(t.value, type::TextureDimension::k1d); EXPECT_FALSE(p->has_error()); } @@ -44,7 +44,7 @@ TEST_F(ParserImplTest, SampledTextureType_1dArray_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k1dArray); + EXPECT_EQ(t.value, type::TextureDimension::k1dArray); EXPECT_FALSE(p->has_error()); } @@ -53,7 +53,7 @@ TEST_F(ParserImplTest, SampledTextureType_2d_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k2d); + EXPECT_EQ(t.value, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, SampledTextureType_2dArray_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k2dArray); + EXPECT_EQ(t.value, type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -71,7 +71,7 @@ TEST_F(ParserImplTest, SampledTextureType_3d_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k3d); + EXPECT_EQ(t.value, type::TextureDimension::k3d); EXPECT_FALSE(p->has_error()); } @@ -80,7 +80,7 @@ TEST_F(ParserImplTest, SampledTextureType_Cube_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::kCube); + EXPECT_EQ(t.value, type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); } @@ -89,7 +89,7 @@ TEST_F(ParserImplTest, SampledTextureType_kCubeArray_Old) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::kCubeArray); + EXPECT_EQ(t.value, type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); } @@ -98,7 +98,7 @@ TEST_F(ParserImplTest, SampledTextureType_1d) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k1d); + EXPECT_EQ(t.value, type::TextureDimension::k1d); EXPECT_FALSE(p->has_error()); } @@ -107,7 +107,7 @@ TEST_F(ParserImplTest, SampledTextureType_1dArray) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k1dArray); + EXPECT_EQ(t.value, type::TextureDimension::k1dArray); EXPECT_FALSE(p->has_error()); } @@ -116,7 +116,7 @@ TEST_F(ParserImplTest, SampledTextureType_2d) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k2d); + EXPECT_EQ(t.value, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -125,7 +125,7 @@ TEST_F(ParserImplTest, SampledTextureType_2dArray) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k2dArray); + EXPECT_EQ(t.value, type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -134,7 +134,7 @@ TEST_F(ParserImplTest, SampledTextureType_3d) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k3d); + EXPECT_EQ(t.value, type::TextureDimension::k3d); EXPECT_FALSE(p->has_error()); } @@ -143,7 +143,7 @@ TEST_F(ParserImplTest, SampledTextureType_Cube) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::kCube); + EXPECT_EQ(t.value, type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); } @@ -152,7 +152,7 @@ TEST_F(ParserImplTest, SampledTextureType_kCubeArray) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::kCubeArray); + EXPECT_EQ(t.value, type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_sampler_type_test.cc b/src/reader/wgsl/parser_impl_sampler_type_test.cc index b4303cdc2c..ce98c32616 100644 --- a/src/reader/wgsl/parser_impl_sampler_type_test.cc +++ b/src/reader/wgsl/parser_impl_sampler_type_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/sampler_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/sampler_type.h" namespace tint { namespace reader { @@ -37,8 +37,8 @@ TEST_F(ParserImplTest, SamplerType_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - EXPECT_FALSE(t->As()->IsComparison()); + ASSERT_TRUE(t->Is()); + EXPECT_FALSE(t->As()->IsComparison()); EXPECT_FALSE(p->has_error()); } @@ -48,8 +48,8 @@ TEST_F(ParserImplTest, SamplerType_ComparisonSampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - EXPECT_TRUE(t->As()->IsComparison()); + ASSERT_TRUE(t->Is()); + EXPECT_TRUE(t->As()->IsComparison()); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_storage_texture_type_test.cc b/src/reader/wgsl/parser_impl_storage_texture_type_test.cc index 82d97fec9f..d145af8455 100644 --- a/src/reader/wgsl/parser_impl_storage_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_storage_texture_type_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/storage_texture_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/storage_texture_type.h" namespace tint { namespace reader { @@ -35,7 +35,7 @@ TEST_F(ParserImplTest, StorageTextureType_1d) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k1d); + EXPECT_EQ(t.value, type::TextureDimension::k1d); EXPECT_FALSE(p->has_error()); } @@ -44,7 +44,7 @@ TEST_F(ParserImplTest, StorageTextureType_1dArray) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k1dArray); + EXPECT_EQ(t.value, type::TextureDimension::k1dArray); EXPECT_FALSE(p->has_error()); } @@ -53,7 +53,7 @@ TEST_F(ParserImplTest, StorageTextureType_2d) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k2d); + EXPECT_EQ(t.value, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, StorageTextureType_2dArray) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k2dArray); + EXPECT_EQ(t.value, type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -71,7 +71,7 @@ TEST_F(ParserImplTest, StorageTextureType_3d) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::type::TextureDimension::k3d); + EXPECT_EQ(t.value, type::TextureDimension::k3d); EXPECT_FALSE(p->has_error()); } @@ -88,7 +88,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly1d_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -98,7 +98,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly1dArray_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -108,7 +108,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly2d_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -118,7 +118,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly2dArray_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -128,7 +128,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly3d_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k3d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -138,7 +138,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly1d_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -148,7 +148,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly1dArray_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -158,7 +158,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly2d_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -168,7 +168,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly2dArray_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -178,7 +178,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly3d_Old) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k3d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -188,7 +188,7 @@ TEST_F(ParserImplTest, StorageTextureType_ro_1d) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -198,7 +198,7 @@ TEST_F(ParserImplTest, StorageTextureType_ro_1dArray) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -208,7 +208,7 @@ TEST_F(ParserImplTest, StorageTextureType_ro_2d) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -218,7 +218,7 @@ TEST_F(ParserImplTest, StorageTextureType_ro_2dArray) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -228,7 +228,7 @@ TEST_F(ParserImplTest, StorageTextureType_ro_3d) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k3d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kReadOnly); EXPECT_FALSE(p->has_error()); } @@ -238,7 +238,7 @@ TEST_F(ParserImplTest, StorageTextureType_wo_1d) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -248,7 +248,7 @@ TEST_F(ParserImplTest, StorageTextureType_wo_1dArray) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k1dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k1dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -258,7 +258,7 @@ TEST_F(ParserImplTest, StorageTextureType_wo_2d) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -268,7 +268,7 @@ TEST_F(ParserImplTest, StorageTextureType_wo_2dArray) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k2dArray); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k2dArray); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } @@ -278,7 +278,7 @@ TEST_F(ParserImplTest, StorageTextureType_wo_3d) { auto t = p->storage_texture_type_access_control(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(std::get<0>(t.value), ast::type::TextureDimension::k3d); + EXPECT_EQ(std::get<0>(t.value), type::TextureDimension::k3d); EXPECT_EQ(std::get<1>(t.value), ast::AccessControl::kWriteOnly); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc index a66837b1ce..bbfdce15b8 100644 --- a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/i32_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/i32_type.h" namespace tint { namespace reader { @@ -26,7 +26,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) { auto p = parser("{a : i32;}"); auto& mod = p->get_module(); - auto* i32 = mod.create(); + auto* i32 = mod.create(); auto m = p->expect_struct_body_decl(); ASSERT_FALSE(p->has_error()); diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index b218608e76..9680c4d987 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -14,7 +14,7 @@ #include "gtest/gtest.h" #include "src/ast/struct_block_decoration.h" -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" diff --git a/src/reader/wgsl/parser_impl_struct_member_test.cc b/src/reader/wgsl/parser_impl_struct_member_test.cc index f5a9fd06aa..554e1d7b79 100644 --- a/src/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/reader/wgsl/parser_impl_struct_member_test.cc @@ -14,9 +14,9 @@ #include "gtest/gtest.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/i32_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/i32_type.h" namespace tint { namespace reader { @@ -27,7 +27,7 @@ TEST_F(ParserImplTest, StructMember_Parses) { auto p = parser("a : i32;"); auto& mod = p->get_module(); - auto* i32 = mod.create(); + auto* i32 = mod.create(); auto decos = p->decoration_list(); EXPECT_FALSE(decos.errored); @@ -53,7 +53,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { auto p = parser("[[offset(2)]] a : i32;"); auto& mod = p->get_module(); - auto* i32 = mod.create(); + auto* i32 = mod.create(); auto decos = p->decoration_list(); EXPECT_FALSE(decos.errored); @@ -84,7 +84,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { [[offset(4)]] a : i32;)"); auto& mod = p->get_module(); - auto* i32 = mod.create(); + auto* i32 = mod.create(); auto decos = p->decoration_list(); EXPECT_FALSE(decos.errored); diff --git a/src/reader/wgsl/parser_impl_test.cc b/src/reader/wgsl/parser_impl_test.cc index 95d28cfaae..1c212088f2 100644 --- a/src/reader/wgsl/parser_impl_test.cc +++ b/src/reader/wgsl/parser_impl_test.cc @@ -15,7 +15,7 @@ #include "src/reader/wgsl/parser_impl.h" #include "gtest/gtest.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/reader/wgsl/parser_impl_test_helper.h" namespace tint { diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc index 88bc7d37b1..df3f0b6ac6 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -13,16 +13,16 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/u32_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/access_control_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/u32_type.h" namespace tint { namespace reader { @@ -45,8 +45,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_FALSE(t->As()->IsComparison()); + ASSERT_TRUE(t->Is()); + ASSERT_FALSE(t->As()->IsComparison()); } TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsComparison()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsComparison()); } TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { @@ -67,10 +67,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { @@ -80,11 +79,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { @@ -94,11 +92,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { @@ -108,11 +105,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k3d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k3d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid_Old) { @@ -163,11 +159,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { @@ -177,11 +172,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { @@ -191,11 +185,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k3d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k3d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) { @@ -245,12 +238,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE( - t->As()->type()->Is()); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) { @@ -302,17 +293,16 @@ TEST_F(ParserImplTest, EXPECT_FALSE(ac.errored); ASSERT_NE(ac.value, nullptr); - ASSERT_TRUE(ac->Is()); - EXPECT_EQ(ac->As()->access_control(), + ASSERT_TRUE(ac->Is()); + EXPECT_EQ(ac->As()->access_control(), ast::AccessControl::kReadOnly); - auto* t = ac->As()->type(); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k1d); + auto* t = ac->As()->type(); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), + type::ImageFormat::kR8Unorm); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k1d); } TEST_F(ParserImplTest, @@ -324,17 +314,16 @@ TEST_F(ParserImplTest, EXPECT_FALSE(ac.errored); ASSERT_NE(ac.value, nullptr); - ASSERT_TRUE(ac->Is()); - EXPECT_EQ(ac->As()->access_control(), + ASSERT_TRUE(ac->Is()); + EXPECT_EQ(ac->As()->access_control(), ast::AccessControl::kWriteOnly); - auto* t = ac->As()->type(); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + auto* t = ac->As()->type(); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), + type::ImageFormat::kR16Float); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType_Old) { @@ -383,17 +372,16 @@ TEST_F(ParserImplTest, EXPECT_FALSE(ac.errored); ASSERT_NE(ac.value, nullptr); - ASSERT_TRUE(ac->Is()); - EXPECT_EQ(ac->As()->access_control(), + ASSERT_TRUE(ac->Is()); + EXPECT_EQ(ac->As()->access_control(), ast::AccessControl::kReadOnly); - auto* t = ac->As()->type(); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k1d); + auto* t = ac->As()->type(); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), + type::ImageFormat::kR8Unorm); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k1d); } TEST_F(ParserImplTest, @@ -405,17 +393,16 @@ TEST_F(ParserImplTest, EXPECT_FALSE(ac.errored); ASSERT_NE(ac.value, nullptr); - ASSERT_TRUE(ac->Is()); - EXPECT_EQ(ac->As()->access_control(), + ASSERT_TRUE(ac->Is()); + EXPECT_EQ(ac->As()->access_control(), ast::AccessControl::kWriteOnly); - auto* t = ac->As()->type(); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + auto* t = ac->As()->type(); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), + type::ImageFormat::kR16Float); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType_old) { @@ -463,12 +450,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), + type::ImageFormat::kR8Unorm); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { @@ -479,12 +465,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->image_format(), - ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->As()->dim(), - ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), + type::ImageFormat::kR16Float); + EXPECT_EQ(t->As()->dim(), type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index efe51a0ae6..da890b5158 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -13,12 +13,12 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" namespace tint { namespace reader { @@ -29,23 +29,23 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) { auto p = parser("type a = i32"); auto& mod = p->get_module(); - auto* i32 = mod.create(); + auto* i32 = mod.create(); auto t = p->type_alias(); EXPECT_FALSE(p->has_error()); EXPECT_FALSE(t.errored); EXPECT_TRUE(t.matched); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - auto* alias = t->As(); - ASSERT_TRUE(alias->type()->Is()); + ASSERT_TRUE(t->Is()); + auto* alias = t->As(); + ASSERT_TRUE(alias->type()->Is()); ASSERT_EQ(alias->type(), i32); } TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { auto p = parser("type a = B"); - ast::type::Struct str(p->get_module().RegisterSymbol("B"), {}); + type::Struct str(p->get_module().RegisterSymbol("B"), {}); p->register_constructed("B", &str); auto t = p->type_alias(); @@ -53,12 +53,12 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { EXPECT_FALSE(t.errored); EXPECT_TRUE(t.matched); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - auto* alias = t->As(); + ASSERT_TRUE(t->Is()); + auto* alias = t->As(); EXPECT_EQ(p->get_module().SymbolToName(alias->symbol()), "a"); - ASSERT_TRUE(alias->type()->Is()); + ASSERT_TRUE(alias->type()->Is()); - auto* s = alias->type()->As(); + auto* s = alias->type()->As(); EXPECT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); EXPECT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 5bb6f9f8f1..f82b065994 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -14,20 +14,20 @@ #include "gtest/gtest.h" #include "src/ast/stride_decoration.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace reader { @@ -48,9 +48,8 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) { auto& mod = p->get_module(); - auto* int_type = mod.create(); - auto* alias_type = - mod.create(mod.RegisterSymbol("A"), int_type); + auto* int_type = mod.create(); + auto* alias_type = mod.create(mod.RegisterSymbol("A"), int_type); p->register_constructed("A", alias_type); @@ -59,9 +58,9 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, alias_type); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* alias = t->As(); + auto* alias = t->As(); EXPECT_EQ(p->get_module().SymbolToName(alias->symbol()), "A"); EXPECT_EQ(alias->type(), int_type); } @@ -81,56 +80,56 @@ TEST_F(ParserImplTest, TypeDecl_Bool) { auto p = parser("bool"); auto& mod = p->get_module(); - auto* bool_type = mod.create(); + auto* bool_type = mod.create(); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, bool_type); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); } TEST_F(ParserImplTest, TypeDecl_F32) { auto p = parser("f32"); auto& mod = p->get_module(); - auto* float_type = mod.create(); + auto* float_type = mod.create(); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, float_type); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); } TEST_F(ParserImplTest, TypeDecl_I32) { auto p = parser("i32"); auto& mod = p->get_module(); - auto* int_type = mod.create(); + auto* int_type = mod.create(); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, int_type); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); } TEST_F(ParserImplTest, TypeDecl_U32) { auto p = parser("u32"); auto& mod = p->get_module(); - auto* uint_type = mod.create(); + auto* uint_type = mod.create(); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, uint_type); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); } struct VecData { @@ -152,8 +151,8 @@ TEST_P(VecTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t->Is()); - EXPECT_EQ(t->As()->size(), params.count); + EXPECT_TRUE(t->Is()); + EXPECT_EQ(t->As()->size(), params.count); } INSTANTIATE_TEST_SUITE_P(ParserImplTest, VecTest, @@ -240,10 +239,10 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* ptr = t->As(); - ASSERT_TRUE(ptr->type()->Is()); + auto* ptr = t->As(); + ASSERT_TRUE(ptr->type()->Is()); ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); } @@ -254,15 +253,15 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* ptr = t->As(); - ASSERT_TRUE(ptr->type()->Is()); + auto* ptr = t->As(); + ASSERT_TRUE(ptr->type()->Is()); ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); - auto* vec = ptr->type()->As(); + auto* vec = ptr->type()->As(); ASSERT_EQ(vec->size(), 2u); - ASSERT_TRUE(vec->type()->Is()); + ASSERT_TRUE(vec->type()->Is()); } TEST_F(ParserImplTest, TypeDecl_Ptr_MissingLessThan) { @@ -352,12 +351,12 @@ TEST_F(ParserImplTest, TypeDecl_Array) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* a = t->As(); + auto* a = t->As(); ASSERT_FALSE(a->IsRuntimeArray()); ASSERT_EQ(a->size(), 5u); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type()->Is()); ASSERT_FALSE(a->has_array_stride()); } @@ -368,12 +367,12 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* a = t->As(); + auto* a = t->As(); ASSERT_FALSE(a->IsRuntimeArray()); ASSERT_EQ(a->size(), 5u); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type()->Is()); ASSERT_TRUE(a->has_array_stride()); EXPECT_EQ(a->array_stride(), 16u); } @@ -385,11 +384,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Stride) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* a = t->As(); + auto* a = t->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type()->Is()); ASSERT_TRUE(a->has_array_stride()); EXPECT_EQ(a->array_stride(), 16u); } @@ -401,11 +400,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* a = t->As(); + auto* a = t->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type()->Is()); auto& decos = a->decorations(); ASSERT_EQ(decos.size(), 2u); @@ -422,11 +421,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* a = t->As(); + auto* a = t->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type()->Is()); auto& decos = a->decorations(); ASSERT_EQ(decos.size(), 2u); @@ -525,11 +524,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); - auto* a = t->As(); + auto* a = t->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type()->Is()); + ASSERT_TRUE(a->type()->Is()); } TEST_F(ParserImplTest, TypeDecl_Array_BadType) { @@ -622,8 +621,8 @@ TEST_P(MatrixTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t->Is()); - auto* mat = t->As(); + EXPECT_TRUE(t->Is()); + auto* mat = t->As(); EXPECT_EQ(mat->rows(), params.rows); EXPECT_EQ(mat->columns(), params.columns); } @@ -740,49 +739,49 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) { auto p = parser("sampler"); auto& mod = p->get_module(); - auto* type = mod.create(ast::type::SamplerKind::kSampler); + auto* type = mod.create(type::SamplerKind::kSampler); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t->Is()); - ASSERT_FALSE(t->As()->IsComparison()); + ASSERT_TRUE(t->Is()); + ASSERT_FALSE(t->As()->IsComparison()); } TEST_F(ParserImplTest, TypeDecl_Texture_Old) { auto p = parser("texture_sampled_cube"); auto& mod = p->get_module(); - auto* type = mod.create( - ast::type::TextureDimension::kCube, ty.f32); + auto* type = + mod.create(type::TextureDimension::kCube, ty.f32); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); } TEST_F(ParserImplTest, TypeDecl_Texture) { auto p = parser("texture_cube"); auto& mod = p->get_module(); - auto* type = mod.create( - ast::type::TextureDimension::kCube, ty.f32); + auto* type = + mod.create(type::TextureDimension::kCube, ty.f32); auto t = p->type_decl(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type()->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->type()->Is()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_variable_decl_test.cc b/src/reader/wgsl/parser_impl_variable_decl_test.cc index 3e30af0ac5..51189d5c9c 100644 --- a/src/reader/wgsl/parser_impl_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_variable_decl_test.cc @@ -13,10 +13,10 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/f32_type.h" namespace tint { namespace reader { @@ -31,7 +31,7 @@ TEST_F(ParserImplTest, VariableDecl_Parses) { EXPECT_FALSE(v.errored); EXPECT_EQ(v->name, "my_var"); EXPECT_NE(v->type, nullptr); - EXPECT_TRUE(v->type->Is()); + EXPECT_TRUE(v->type->Is()); EXPECT_EQ(v->source.range.begin.line, 1u); EXPECT_EQ(v->source.range.begin.column, 5u); @@ -66,7 +66,7 @@ TEST_F(ParserImplTest, VariableDecl_WithStorageClass) { EXPECT_FALSE(v.errored); EXPECT_FALSE(p->has_error()); EXPECT_EQ(v->name, "my_var"); - EXPECT_TRUE(v->type->Is()); + EXPECT_TRUE(v->type->Is()); EXPECT_EQ(v->storage_class, ast::StorageClass::kPrivate); EXPECT_EQ(v->source.range.begin.line, 1u); diff --git a/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc b/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc index b8763fe4be..86e423cba6 100644 --- a/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc +++ b/src/reader/wgsl/parser_impl_variable_ident_decl_test.cc @@ -15,12 +15,12 @@ #include "gtest/gtest.h" #include "src/ast/struct.h" #include "src/ast/struct_block_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/access_control_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" namespace tint { namespace reader { @@ -34,7 +34,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); + ASSERT_TRUE(decl->type->Is()); ASSERT_EQ(decl->source.range.begin.line, 1u); ASSERT_EQ(decl->source.range.begin.column, 1u); @@ -90,11 +90,11 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Read) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); - EXPECT_TRUE(decl->type->As()->IsReadOnly()); - ASSERT_TRUE(decl->type->As() + ASSERT_TRUE(decl->type->Is()); + EXPECT_TRUE(decl->type->As()->IsReadOnly()); + ASSERT_TRUE(decl->type->As() ->type() - ->Is()); + ->Is()); } TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Write) { @@ -105,11 +105,11 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Write) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); - EXPECT_TRUE(decl->type->As()->IsWriteOnly()); - ASSERT_TRUE(decl->type->As() + ASSERT_TRUE(decl->type->Is()); + EXPECT_TRUE(decl->type->As()->IsWriteOnly()); + ASSERT_TRUE(decl->type->As() ->type() - ->Is()); + ->Is()); } TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) { @@ -133,8 +133,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); - EXPECT_TRUE(decl->type->As()->IsReadOnly()); + ASSERT_TRUE(decl->type->Is()); + EXPECT_TRUE(decl->type->As()->IsReadOnly()); } TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) { @@ -158,8 +158,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); - EXPECT_TRUE(decl->type->As()->IsReadWrite()); + ASSERT_TRUE(decl->type->Is()); + EXPECT_TRUE(decl->type->As()->IsReadWrite()); } TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) { diff --git a/src/scope_stack_test.cc b/src/scope_stack_test.cc index 7e58c35bb8..f5c9f841aa 100644 --- a/src/scope_stack_test.cc +++ b/src/scope_stack_test.cc @@ -15,9 +15,9 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/symbol.h" +#include "src/type/f32_type.h" namespace tint { namespace { diff --git a/src/transform/bound_array_accessors.cc b/src/transform/bound_array_accessors.cc index c7ce85e0d1..bdfb9384d3 100644 --- a/src/transform/bound_array_accessors.cc +++ b/src/transform/bound_array_accessors.cc @@ -39,15 +39,15 @@ #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/array_type.h" +#include "src/type/matrix_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace transform { @@ -71,8 +71,8 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform( ast::CloneContext* ctx, diag::List* diags) { auto* ret_type = expr->array()->result_type()->UnwrapAll(); - if (!ret_type->Is() && !ret_type->Is() && - !ret_type->Is()) { + if (!ret_type->Is() && !ret_type->Is() && + !ret_type->Is()) { return nullptr; } @@ -80,15 +80,15 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform( using u32 = ast::Builder::u32; uint32_t size = 0; - bool is_vec = ret_type->Is(); - bool is_arr = ret_type->Is(); + bool is_vec = ret_type->Is(); + bool is_arr = ret_type->Is(); if (is_vec || is_arr) { - size = is_vec ? ret_type->As()->size() - : ret_type->As()->size(); + size = is_vec ? ret_type->As()->size() + : ret_type->As()->size(); } else { // The row accessor would have been an embedded array accessor and already // handled, so we just need to do columns here. - size = ret_type->As()->columns(); + size = ret_type->As()->columns(); } auto* const old_idx = expr->idx_expr(); diff --git a/src/transform/emit_vertex_point_size.cc b/src/transform/emit_vertex_point_size.cc index 1628d63e2a..a46a958553 100644 --- a/src/transform/emit_vertex_point_size.cc +++ b/src/transform/emit_vertex_point_size.cc @@ -23,9 +23,9 @@ #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type_manager.h" #include "src/ast/variable.h" +#include "src/type/f32_type.h" +#include "src/type/type_manager.h" namespace tint { namespace transform { @@ -47,7 +47,7 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) { return out; } - auto* f32 = out.module.create(); + auto* f32 = out.module.create(); // Declare the pointsize builtin output variable. auto* pointsize_var = out.module.create( diff --git a/src/transform/first_index_offset.cc b/src/transform/first_index_offset.cc index 7e6bfda473..df878ac343 100644 --- a/src/transform/first_index_offset.cc +++ b/src/transform/first_index_offset.cc @@ -42,13 +42,13 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decoration.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" #include "src/type_determiner.h" namespace tint { @@ -196,7 +196,7 @@ uint32_t FirstIndexOffset::GetFirstInstanceOffset() { } ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) { - auto* u32_type = mod->create(); + auto* u32_type = mod->create(); ast::StructMemberList members; uint32_t offset = 0; if (has_vertex_index_) { @@ -224,7 +224,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) { ast::StructDecorationList decos; decos.push_back(mod->create(Source{})); - auto* struct_type = mod->create( + auto* struct_type = mod->create( mod->RegisterSymbol(kStructName), mod->create(Source{}, std::move(members), std::move(decos))); @@ -268,9 +268,9 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset( mod->create(Source{}, // source mod->RegisterSymbol(original_name), // symbol ast::StorageClass::kNone, // storage_class - mod->create(), // type - true, // is_const - constructor, // constructor + mod->create(), // type + true, // is_const + constructor, // constructor ast::VariableDecorationList{}); // decorations return mod->create(Source{}, var); } diff --git a/src/transform/vertex_pulling.cc b/src/transform/vertex_pulling.cc index ae121f401a..24f6da61e1 100644 --- a/src/transform/vertex_pulling.cc +++ b/src/transform/vertex_pulling.cc @@ -29,16 +29,16 @@ #include "src/ast/struct_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace transform { @@ -261,7 +261,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() { void VertexPulling::State::AddVertexStorageBuffers() { // TODO(idanr): Make this readonly https://github.com/gpuweb/gpuweb/issues/935 // The array inside the struct definition - auto* internal_array_type = out->create( + auto* internal_array_type = out->create( GetU32Type(), 0, ast::ArrayDecorationList{ out->create(Source{}, 4u), @@ -280,7 +280,7 @@ void VertexPulling::State::AddVertexStorageBuffers() { ast::StructDecorationList decos; decos.push_back(out->create(Source{})); - auto* struct_type = out->create( + auto* struct_type = out->create( out->RegisterSymbol(kStructName), out->create(Source{}, std::move(members), std::move(decos))); @@ -463,7 +463,7 @@ ast::Expression* VertexPulling::State::AccessPrimitive( ast::Expression* VertexPulling::State::AccessVec(uint32_t buffer, uint32_t element_stride, - ast::type::Type* base_type, + type::Type* base_type, VertexFormat base_format, uint32_t count) const { ast::ExpressionList expr_list; @@ -476,20 +476,20 @@ ast::Expression* VertexPulling::State::AccessVec(uint32_t buffer, } return out->create( - Source{}, out->create(base_type, count), + Source{}, out->create(base_type, count), std::move(expr_list)); } -ast::type::Type* VertexPulling::State::GetU32Type() const { - return out->create(); +type::Type* VertexPulling::State::GetU32Type() const { + return out->create(); } -ast::type::Type* VertexPulling::State::GetI32Type() const { - return out->create(); +type::Type* VertexPulling::State::GetI32Type() const { + return out->create(); } -ast::type::Type* VertexPulling::State::GetF32Type() const { - return out->create(); +type::Type* VertexPulling::State::GetF32Type() const { + return out->create(); } VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor() = default; diff --git a/src/transform/vertex_pulling.h b/src/transform/vertex_pulling.h index a09cf0f30c..2a75cc5cf6 100644 --- a/src/transform/vertex_pulling.h +++ b/src/transform/vertex_pulling.h @@ -254,14 +254,14 @@ class VertexPulling : public Transform { /// @param count how many elements the vector has ast::Expression* AccessVec(uint32_t buffer, uint32_t element_stride, - ast::type::Type* base_type, + type::Type* base_type, VertexFormat base_format, uint32_t count) const; // Used to grab corresponding types from the type manager - ast::type::Type* GetU32Type() const; - ast::type::Type* GetI32Type() const; - ast::type::Type* GetF32Type() const; + type::Type* GetU32Type() const; + type::Type* GetI32Type() const; + type::Type* GetF32Type() const; ast::Module* const in; ast::Module* const out; diff --git a/src/ast/type/access_control_type.cc b/src/type/access_control_type.cc similarity index 92% rename from src/ast/type/access_control_type.cc rename to src/type/access_control_type.cc index 44e7cbe784..82e0de1f6b 100644 --- a/src/ast/type/access_control_type.cc +++ b/src/type/access_control_type.cc @@ -12,17 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/access_control_type.h" +#include "src/type/access_control_type.h" #include #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::AccessControl); +TINT_INSTANTIATE_CLASS_ID(tint::type::AccessControl); namespace tint { -namespace ast { namespace type { AccessControl::AccessControl(ast::AccessControl access, Type* subtype) @@ -64,5 +63,4 @@ AccessControl* AccessControl::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/access_control_type.h b/src/type/access_control_type.h similarity index 92% rename from src/ast/type/access_control_type.h rename to src/type/access_control_type.h index e018b95a9b..3e0da4816c 100644 --- a/src/ast/type/access_control_type.h +++ b/src/type/access_control_type.h @@ -12,16 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_ACCESS_CONTROL_TYPE_H_ -#define SRC_AST_TYPE_ACCESS_CONTROL_TYPE_H_ +#ifndef SRC_TYPE_ACCESS_CONTROL_TYPE_H_ +#define SRC_TYPE_ACCESS_CONTROL_TYPE_H_ #include #include "src/ast/access_control.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// An access control type. Holds an access setting and pointer to another type. @@ -71,7 +70,6 @@ class AccessControl : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_ACCESS_CONTROL_TYPE_H_ +#endif // SRC_TYPE_ACCESS_CONTROL_TYPE_H_ diff --git a/src/ast/type/access_control_type_test.cc b/src/type/access_control_type_test.cc similarity index 79% rename from src/ast/type/access_control_type_test.cc rename to src/type/access_control_type_test.cc index 882f144eee..5392336a0f 100644 --- a/src/ast/type/access_control_type_test.cc +++ b/src/type/access_control_type_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/access_control_type.h" +#include "src/type/access_control_type.h" #include #include @@ -22,20 +22,19 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -106,23 +105,25 @@ TEST_F(AccessControlTest, MinBufferBindingSizeU32) { TEST_F(AccessControlTest, MinBufferBindingSizeArray) { U32 u32; - Array array(&u32, 4, ArrayDecorationList{create(4)}); + Array array(&u32, 4, + ast::ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(AccessControlTest, MinBufferBindingSizeRuntimeArray) { U32 u32; - Array array(&u32, 0, ArrayDecorationList{create(4)}); + Array array(&u32, 0, + ast::ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(AccessControlTest, MinBufferBindingSizeStruct) { auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)})}, + ast::StructDecorationList{}); auto* struct_type = ty.struct_("struct_type", str); AccessControl at{ast::AccessControl::kReadOnly, struct_type}; @@ -138,23 +139,25 @@ TEST_F(AccessControlTest, BaseAlignmentU32) { TEST_F(AccessControlTest, BaseAlignmentArray) { U32 u32; - Array array(&u32, 4, ArrayDecorationList{create(4)}); + Array array(&u32, 4, + ast::ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); } TEST_F(AccessControlTest, BaseAlignmentRuntimeArray) { U32 u32; - Array array(&u32, 0, ArrayDecorationList{create(4)}); + Array array(&u32, 0, + ast::ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); } TEST_F(AccessControlTest, BaseAlignmentStruct) { auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)})}, + ast::StructDecorationList{}); auto* struct_type = ty.struct_("struct_type", str); AccessControl at{ast::AccessControl::kReadOnly, struct_type}; @@ -164,5 +167,4 @@ TEST_F(AccessControlTest, BaseAlignmentStruct) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/alias_type.cc b/src/type/alias_type.cc similarity index 91% rename from src/ast/type/alias_type.cc rename to src/type/alias_type.cc index b8632de4c3..1a21feadbd 100644 --- a/src/ast/type/alias_type.cc +++ b/src/type/alias_type.cc @@ -12,17 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/alias_type.h" +#include "src/type/alias_type.h" #include #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Alias); +TINT_INSTANTIATE_CLASS_ID(tint::type::Alias); namespace tint { -namespace ast { namespace type { Alias::Alias(const Symbol& sym, Type* subtype) @@ -51,5 +50,4 @@ Alias* Alias::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/alias_type.h b/src/type/alias_type.h similarity index 92% rename from src/ast/type/alias_type.h rename to src/type/alias_type.h index 7bc3bc2c65..c1f858d97f 100644 --- a/src/ast/type/alias_type.h +++ b/src/type/alias_type.h @@ -12,16 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_ALIAS_TYPE_H_ -#define SRC_AST_TYPE_ALIAS_TYPE_H_ +#ifndef SRC_TYPE_ALIAS_TYPE_H_ +#define SRC_TYPE_ALIAS_TYPE_H_ #include -#include "src/ast/type/type.h" #include "src/symbol.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A type alias type. Holds a name and pointer to another type. @@ -65,7 +64,6 @@ class Alias : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_ALIAS_TYPE_H_ +#endif // SRC_TYPE_ALIAS_TYPE_H_ diff --git a/src/ast/type/alias_type_test.cc b/src/type/alias_type_test.cc similarity index 79% rename from src/ast/type/alias_type_test.cc rename to src/type/alias_type_test.cc index c1c59a49a5..52430f25c0 100644 --- a/src/ast/type/alias_type_test.cc +++ b/src/type/alias_type_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/alias_type.h" +#include "src/type/alias_type.h" #include #include @@ -22,20 +22,19 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -104,7 +103,7 @@ TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) { TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) { auto* a = ty.alias("a_type", ty.u32); auto* aa = ty.alias("aa_type", a); - Pointer paa{aa, StorageClass::kUniform}; + Pointer paa{aa, ast::StorageClass::kUniform}; auto* apaa = ty.alias("paa_type", &paa); auto* aapaa = ty.alias("aapaa_type", apaa); @@ -117,8 +116,8 @@ TEST_F(AliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) { auto* a = ty.alias("a_type", ty.u32); auto* aa = ty.alias("aa_type", a); - Pointer paa{aa, StorageClass::kUniform}; - Pointer ppaa{&paa, StorageClass::kUniform}; + Pointer paa{aa, ast::StorageClass::kUniform}; + Pointer ppaa{&paa, ast::StorageClass::kUniform}; auto* appaa = ty.alias("appaa_type", &ppaa); EXPECT_EQ(appaa->UnwrapAll(), &paa); } @@ -126,11 +125,11 @@ TEST_F(AliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) { TEST_F(AliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) { auto* a = ty.alias("a_type", ty.u32); auto* aa = ty.alias("aa_type", a); - Pointer paa{aa, StorageClass::kUniform}; + Pointer paa{aa, ast::StorageClass::kUniform}; auto* apaa = ty.alias("apaa_type", &paa); auto* aapaa = ty.alias("aapaa_type", apaa); - Pointer paapaa{aapaa, StorageClass::kUniform}; + Pointer paapaa{aapaa, ast::StorageClass::kUniform}; auto* apaapaa = ty.alias("apaapaa_type", &paapaa); EXPECT_EQ(apaapaa->UnwrapAll(), &paa); @@ -138,13 +137,13 @@ TEST_F(AliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) { TEST_F(AliasTest, UnwrapAll_AccessControlPointer) { AccessControl a{ast::AccessControl::kReadOnly, ty.u32}; - Pointer pa{&a, StorageClass::kUniform}; + Pointer pa{&a, ast::StorageClass::kUniform}; EXPECT_EQ(pa.type(), &a); EXPECT_EQ(pa.UnwrapAll(), ty.u32); } TEST_F(AliasTest, UnwrapAll_PointerAccessControl) { - Pointer p{ty.u32, StorageClass::kUniform}; + Pointer p{ty.u32, ast::StorageClass::kUniform}; AccessControl a{ast::AccessControl::kReadOnly, &p}; EXPECT_EQ(a.type(), &p); @@ -158,8 +157,8 @@ TEST_F(AliasTest, MinBufferBindingSizeU32) { TEST_F(AliasTest, MinBufferBindingSizeArray) { Array array(ty.u32, 4, - ArrayDecorationList{ - create(4), + ast::ArrayDecorationList{ + create(4), }); auto* alias = ty.alias("alias", &array); EXPECT_EQ(16u, alias->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); @@ -167,8 +166,8 @@ TEST_F(AliasTest, MinBufferBindingSizeArray) { TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) { Array array(ty.u32, 0, - ArrayDecorationList{ - create(4), + ast::ArrayDecorationList{ + create(4), }); auto* alias = ty.alias("alias", &array); EXPECT_EQ(4u, alias->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); @@ -176,9 +175,9 @@ TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) { TEST_F(AliasTest, MinBufferBindingSizeStruct) { auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)})}, + ast::StructDecorationList{}); auto* struct_type = ty.struct_("struct_type", str); auto* alias = ty.alias("alias", struct_type); @@ -193,8 +192,8 @@ TEST_F(AliasTest, BaseAlignmentU32) { TEST_F(AliasTest, BaseAlignmentArray) { Array array(ty.u32, 4, - ArrayDecorationList{ - create(4), + ast::ArrayDecorationList{ + create(4), }); auto* alias = ty.alias("alias", &array); EXPECT_EQ(16u, alias->BaseAlignment(MemoryLayout::kUniformBuffer)); @@ -202,8 +201,8 @@ TEST_F(AliasTest, BaseAlignmentArray) { TEST_F(AliasTest, BaseAlignmentRuntimeArray) { Array array(ty.u32, 0, - ArrayDecorationList{ - create(4), + ast::ArrayDecorationList{ + create(4), }); auto* alias = ty.alias("alias", &array); EXPECT_EQ(16u, alias->BaseAlignment(MemoryLayout::kUniformBuffer)); @@ -211,9 +210,9 @@ TEST_F(AliasTest, BaseAlignmentRuntimeArray) { TEST_F(AliasTest, BaseAlignmentStruct) { auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)})}, + ast::StructDecorationList{}); auto* struct_type = ty.struct_("struct_type", str); auto* alias = ty.alias("alias", struct_type); @@ -223,5 +222,4 @@ TEST_F(AliasTest, BaseAlignmentStruct) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/array_type.cc b/src/type/array_type.cc similarity index 89% rename from src/ast/type/array_type.cc rename to src/type/array_type.cc index be71ad7058..7793f03f89 100644 --- a/src/ast/type/array_type.cc +++ b/src/type/array_type.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/array_type.h" +#include "src/type/array_type.h" #include #include @@ -20,15 +20,14 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" #include "src/ast/stride_decoration.h" -#include "src/ast/type/vector_type.h" +#include "src/type/vector_type.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Array); +TINT_INSTANTIATE_CLASS_ID(tint::type::Array); namespace tint { -namespace ast { namespace type { -Array::Array(Type* subtype, uint32_t size, ArrayDecorationList decorations) +Array::Array(Type* subtype, uint32_t size, ast::ArrayDecorationList decorations) : subtype_(subtype), size_(size), decos_(decorations) {} Array::Array(Array&&) = default; @@ -68,7 +67,7 @@ uint64_t Array::BaseAlignment(MemoryLayout mem_layout) const { uint32_t Array::array_stride() const { for (auto* deco : decos_) { - if (auto* stride = deco->As()) { + if (auto* stride = deco->As()) { return stride->stride(); } } @@ -77,7 +76,7 @@ uint32_t Array::array_stride() const { bool Array::has_array_stride() const { for (auto* deco : decos_) { - if (deco->Is()) { + if (deco->Is()) { return true; } } @@ -102,5 +101,4 @@ Array* Array::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/array_type.h b/src/type/array_type.h similarity index 87% rename from src/ast/type/array_type.h rename to src/type/array_type.h index eafb2048e8..404fa3b376 100644 --- a/src/ast/type/array_type.h +++ b/src/type/array_type.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_ARRAY_TYPE_H_ -#define SRC_AST_TYPE_ARRAY_TYPE_H_ +#ifndef SRC_TYPE_ARRAY_TYPE_H_ +#define SRC_TYPE_ARRAY_TYPE_H_ #include @@ -21,10 +21,9 @@ #include #include "src/ast/array_decoration.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// An array type. If size is zero then it is a runtime array. @@ -35,7 +34,7 @@ class Array : public Castable { /// @param size the number of elements in the array. `0` represents a /// runtime-sized array. /// @param decorations the array decorations - Array(Type* subtype, uint32_t size, ArrayDecorationList decorations); + Array(Type* subtype, uint32_t size, ast::ArrayDecorationList decorations); /// Move constructor Array(Array&&); ~Array() override; @@ -55,7 +54,7 @@ class Array : public Castable { uint64_t BaseAlignment(MemoryLayout mem_layout) const override; /// @returns the array decorations - const ArrayDecorationList& decorations() const { return decos_; } + const ast::ArrayDecorationList& decorations() const { return decos_; } /// @returns the array stride or 0 if none set. uint32_t array_stride() const; @@ -78,11 +77,10 @@ class Array : public Castable { private: Type* const subtype_; uint32_t const size_; - ArrayDecorationList const decos_; + ast::ArrayDecorationList const decos_; }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_ARRAY_TYPE_H_ +#endif // SRC_TYPE_ARRAY_TYPE_H_ diff --git a/src/ast/type/array_type_test.cc b/src/type/array_type_test.cc similarity index 70% rename from src/ast/type/array_type_test.cc rename to src/type/array_type_test.cc index 8d61e27f97..54bc12ad70 100644 --- a/src/ast/type/array_type_test.cc +++ b/src/type/array_type_test.cc @@ -12,26 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/array_type.h" +#include "src/type/array_type.h" #include #include #include "src/ast/stride_decoration.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -39,7 +38,7 @@ using ArrayTest = TestHelper; TEST_F(ArrayTest, CreateSizedArray) { U32 u32; - Array arr{&u32, 3, ArrayDecorationList{}}; + Array arr{&u32, 3, ast::ArrayDecorationList{}}; EXPECT_EQ(arr.type(), &u32); EXPECT_EQ(arr.size(), 3u); EXPECT_TRUE(arr.Is()); @@ -48,7 +47,7 @@ TEST_F(ArrayTest, CreateSizedArray) { TEST_F(ArrayTest, CreateRuntimeArray) { U32 u32; - Array arr{&u32, 0, ArrayDecorationList{}}; + Array arr{&u32, 0, ast::ArrayDecorationList{}}; EXPECT_EQ(arr.type(), &u32); EXPECT_EQ(arr.size(), 0u); EXPECT_TRUE(arr.Is()); @@ -58,7 +57,7 @@ TEST_F(ArrayTest, CreateRuntimeArray) { TEST_F(ArrayTest, Is) { I32 i32; - Array arr{&i32, 3, ArrayDecorationList{}}; + Array arr{&i32, 3, ast::ArrayDecorationList{}}; Type* ty = &arr; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -77,55 +76,59 @@ TEST_F(ArrayTest, Is) { TEST_F(ArrayTest, TypeName) { I32 i32; - Array arr{&i32, 0, ArrayDecorationList{}}; + Array arr{&i32, 0, ast::ArrayDecorationList{}}; EXPECT_EQ(arr.type_name(), "__array__i32"); } TEST_F(ArrayTest, TypeName_RuntimeArray) { I32 i32; - Array arr{&i32, 3, ArrayDecorationList{}}; + Array arr{&i32, 3, ast::ArrayDecorationList{}}; EXPECT_EQ(arr.type_name(), "__array__i32_3"); } TEST_F(ArrayTest, TypeName_WithStride) { I32 i32; - Array arr{&i32, 3, ArrayDecorationList{create(16)}}; + Array arr{&i32, 3, + ast::ArrayDecorationList{create(16)}}; EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16"); } TEST_F(ArrayTest, MinBufferBindingSizeNoStride) { U32 u32; - Array arr(&u32, 4, ArrayDecorationList{}); + Array arr(&u32, 4, ast::ArrayDecorationList{}); EXPECT_EQ(0u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(ArrayTest, MinBufferBindingSizeArray) { U32 u32; - Array arr(&u32, 4, ArrayDecorationList{create(4)}); + Array arr(&u32, 4, + ast::ArrayDecorationList{create(4)}); EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(ArrayTest, MinBufferBindingSizeRuntimeArray) { U32 u32; - Array arr(&u32, 0, ArrayDecorationList{create(4)}); + Array arr(&u32, 0, + ast::ArrayDecorationList{create(4)}); EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(ArrayTest, BaseAlignmentArray) { U32 u32; - Array arr(&u32, 4, ArrayDecorationList{create(4)}); + Array arr(&u32, 4, + ast::ArrayDecorationList{create(4)}); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); } TEST_F(ArrayTest, BaseAlignmentRuntimeArray) { U32 u32; - Array arr(&u32, 0, ArrayDecorationList{create(4)}); + Array arr(&u32, 0, + ast::ArrayDecorationList{create(4)}); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); } } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/bool_type.cc b/src/type/bool_type.cc similarity index 88% rename from src/ast/type/bool_type.cc rename to src/type/bool_type.cc index 7c26c86379..ead02f8c43 100644 --- a/src/ast/type/bool_type.cc +++ b/src/type/bool_type.cc @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/bool_type.h" +#include "src/type/bool_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Bool); +TINT_INSTANTIATE_CLASS_ID(tint::type::Bool); namespace tint { -namespace ast { namespace type { Bool::Bool() = default; @@ -38,5 +37,4 @@ Bool* Bool::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/bool_type.h b/src/type/bool_type.h similarity index 86% rename from src/ast/type/bool_type.h rename to src/type/bool_type.h index 11f5338046..fa3f01da45 100644 --- a/src/ast/type/bool_type.h +++ b/src/type/bool_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_BOOL_TYPE_H_ -#define SRC_AST_TYPE_BOOL_TYPE_H_ +#ifndef SRC_TYPE_BOOL_TYPE_H_ +#define SRC_TYPE_BOOL_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A boolean type @@ -42,7 +41,6 @@ class Bool : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_BOOL_TYPE_H_ +#endif // SRC_TYPE_BOOL_TYPE_H_ diff --git a/src/ast/type/bool_type_test.cc b/src/type/bool_type_test.cc similarity index 74% rename from src/ast/type/bool_type_test.cc rename to src/type/bool_type_test.cc index d6c6f253a1..552857b4bc 100644 --- a/src/ast/type/bool_type_test.cc +++ b/src/type/bool_type_test.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/bool_type.h" +#include "src/type/bool_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -63,5 +62,4 @@ TEST_F(BoolTest, MinBufferBindingSize) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/depth_texture_type.cc b/src/type/depth_texture_type.cc similarity index 91% rename from src/ast/type/depth_texture_type.cc rename to src/type/depth_texture_type.cc index 95b55aa464..770ced4768 100644 --- a/src/ast/type/depth_texture_type.cc +++ b/src/type/depth_texture_type.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/depth_texture_type.h" +#include "src/type/depth_texture_type.h" #include #include @@ -20,10 +20,9 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::DepthTexture); +TINT_INSTANTIATE_CLASS_ID(tint::type::DepthTexture); namespace tint { -namespace ast { namespace type { namespace { @@ -57,5 +56,4 @@ DepthTexture* DepthTexture::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/depth_texture_type.h b/src/type/depth_texture_type.h similarity index 86% rename from src/ast/type/depth_texture_type.h rename to src/type/depth_texture_type.h index 02f07d334c..43eed57189 100644 --- a/src/ast/type/depth_texture_type.h +++ b/src/type/depth_texture_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_DEPTH_TEXTURE_TYPE_H_ -#define SRC_AST_TYPE_DEPTH_TEXTURE_TYPE_H_ +#ifndef SRC_TYPE_DEPTH_TEXTURE_TYPE_H_ +#define SRC_TYPE_DEPTH_TEXTURE_TYPE_H_ #include -#include "src/ast/type/texture_type.h" +#include "src/type/texture_type.h" namespace tint { -namespace ast { namespace type { /// A depth texture type. @@ -43,7 +42,6 @@ class DepthTexture : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_DEPTH_TEXTURE_TYPE_H_ +#endif // SRC_TYPE_DEPTH_TEXTURE_TYPE_H_ diff --git a/src/ast/type/depth_texture_type_test.cc b/src/type/depth_texture_type_test.cc similarity index 76% rename from src/ast/type/depth_texture_type_test.cc rename to src/type/depth_texture_type_test.cc index b956f8905b..26be3e9add 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/type/depth_texture_type_test.cc @@ -12,25 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/depth_texture_type.h" +#include "src/type/depth_texture_type.h" -#include "src/ast/test_helper.h" +#include "src/type/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -79,5 +78,4 @@ TEST_F(DepthTextureTest, MinBufferBindingSize) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/f32_type.cc b/src/type/f32_type.cc similarity index 90% rename from src/ast/type/f32_type.cc rename to src/type/f32_type.cc index bfcdc6996c..49611872cc 100644 --- a/src/ast/type/f32_type.cc +++ b/src/type/f32_type.cc @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/f32_type.h" +#include "src/type/f32_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::F32); +TINT_INSTANTIATE_CLASS_ID(tint::type::F32); namespace tint { -namespace ast { namespace type { F32::F32() = default; @@ -46,5 +45,4 @@ F32* F32::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/f32_type.h b/src/type/f32_type.h similarity index 90% rename from src/ast/type/f32_type.h rename to src/type/f32_type.h index 86187f3eaa..55e4224230 100644 --- a/src/ast/type/f32_type.h +++ b/src/type/f32_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_F32_TYPE_H_ -#define SRC_AST_TYPE_F32_TYPE_H_ +#ifndef SRC_TYPE_F32_TYPE_H_ +#define SRC_TYPE_F32_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A float 32 type @@ -52,7 +51,6 @@ class F32 : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_F32_TYPE_H_ +#endif // SRC_TYPE_F32_TYPE_H_ diff --git a/src/ast/type/f32_type_test.cc b/src/type/f32_type_test.cc similarity index 75% rename from src/ast/type/f32_type_test.cc rename to src/type/f32_type_test.cc index 0570b7e239..7a25dc7576 100644 --- a/src/ast/type/f32_type_test.cc +++ b/src/type/f32_type_test.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/f32_type.h" +#include "src/type/f32_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -68,5 +67,4 @@ TEST_F(F32Test, BaseAlignment) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/i32_type.cc b/src/type/i32_type.cc similarity index 90% rename from src/ast/type/i32_type.cc rename to src/type/i32_type.cc index 6b47eb33e1..29fee5e8e8 100644 --- a/src/ast/type/i32_type.cc +++ b/src/type/i32_type.cc @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::I32); +TINT_INSTANTIATE_CLASS_ID(tint::type::I32); namespace tint { -namespace ast { namespace type { I32::I32() = default; @@ -46,5 +45,4 @@ I32* I32::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/i32_type.h b/src/type/i32_type.h similarity index 90% rename from src/ast/type/i32_type.h rename to src/type/i32_type.h index 104d593fb8..cb4421f8ff 100644 --- a/src/ast/type/i32_type.h +++ b/src/type/i32_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_I32_TYPE_H_ -#define SRC_AST_TYPE_I32_TYPE_H_ +#ifndef SRC_TYPE_I32_TYPE_H_ +#define SRC_TYPE_I32_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A signed int 32 type. @@ -52,7 +51,6 @@ class I32 : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_I32_TYPE_H_ +#endif // SRC_TYPE_I32_TYPE_H_ diff --git a/src/ast/type/i32_type_test.cc b/src/type/i32_type_test.cc similarity index 75% rename from src/ast/type/i32_type_test.cc rename to src/type/i32_type_test.cc index 0333d01d34..0fa098a989 100644 --- a/src/ast/type/i32_type_test.cc +++ b/src/type/i32_type_test.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -68,5 +67,4 @@ TEST_F(I32Test, BaseAlignment) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/matrix_type.cc b/src/type/matrix_type.cc similarity index 86% rename from src/ast/type/matrix_type.cc rename to src/type/matrix_type.cc index 12eea4530e..f151654289 100644 --- a/src/ast/type/matrix_type.cc +++ b/src/type/matrix_type.cc @@ -12,19 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/matrix_type.h" +#include "src/type/matrix_type.h" #include #include "src/ast/clone_context.h" #include "src/ast/module.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/array_type.h" +#include "src/type/vector_type.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Matrix); +TINT_INSTANTIATE_CLASS_ID(tint::type::Matrix); namespace tint { -namespace ast { namespace type { Matrix::Matrix(Type* subtype, uint32_t rows, uint32_t columns) @@ -52,7 +51,7 @@ uint64_t Matrix::MinBufferBindingSize(MemoryLayout mem_layout) const { uint64_t Matrix::BaseAlignment(MemoryLayout mem_layout) const { Vector vec(subtype_, rows_); - Array arr(&vec, columns_, ArrayDecorationList{}); + Array arr(&vec, columns_, ast::ArrayDecorationList{}); return arr.BaseAlignment(mem_layout); } @@ -61,5 +60,4 @@ Matrix* Matrix::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/matrix_type.h b/src/type/matrix_type.h similarity index 92% rename from src/ast/type/matrix_type.h rename to src/type/matrix_type.h index 500f43eb83..d37a115b38 100644 --- a/src/ast/type/matrix_type.h +++ b/src/type/matrix_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_MATRIX_TYPE_H_ -#define SRC_AST_TYPE_MATRIX_TYPE_H_ +#ifndef SRC_TYPE_MATRIX_TYPE_H_ +#define SRC_TYPE_MATRIX_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A matrix type @@ -67,7 +66,6 @@ class Matrix : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_MATRIX_TYPE_H_ +#endif // SRC_TYPE_MATRIX_TYPE_H_ diff --git a/src/ast/type/matrix_type_test.cc b/src/type/matrix_type_test.cc similarity index 87% rename from src/ast/type/matrix_type_test.cc rename to src/type/matrix_type_test.cc index fb4c1a7613..c1b6c43628 100644 --- a/src/ast/type/matrix_type_test.cc +++ b/src/type/matrix_type_test.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/matrix_type.h" +#include "src/type/matrix_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -124,5 +123,4 @@ TEST_F(MatrixTest, BaseAlignment2x2) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/multisampled_texture_type.cc b/src/type/multisampled_texture_type.cc similarity index 89% rename from src/ast/type/multisampled_texture_type.cc rename to src/type/multisampled_texture_type.cc index 2ec43209ae..16bb04e76d 100644 --- a/src/ast/type/multisampled_texture_type.cc +++ b/src/type/multisampled_texture_type.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/multisampled_texture_type.h" +#include "src/type/multisampled_texture_type.h" #include #include @@ -20,10 +20,9 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::MultisampledTexture); +TINT_INSTANTIATE_CLASS_ID(tint::type::MultisampledTexture); namespace tint { -namespace ast { namespace type { MultisampledTexture::MultisampledTexture(TextureDimension dim, Type* type) @@ -46,5 +45,4 @@ MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/multisampled_texture_type.h b/src/type/multisampled_texture_type.h similarity index 86% rename from src/ast/type/multisampled_texture_type.h rename to src/type/multisampled_texture_type.h index 4fb45e2577..afe7d6ba4a 100644 --- a/src/ast/type/multisampled_texture_type.h +++ b/src/type/multisampled_texture_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_MULTISAMPLED_TEXTURE_TYPE_H_ -#define SRC_AST_TYPE_MULTISAMPLED_TEXTURE_TYPE_H_ +#ifndef SRC_TYPE_MULTISAMPLED_TEXTURE_TYPE_H_ +#define SRC_TYPE_MULTISAMPLED_TEXTURE_TYPE_H_ #include -#include "src/ast/type/texture_type.h" +#include "src/type/texture_type.h" namespace tint { -namespace ast { namespace type { /// A multisampled texture type. @@ -50,7 +49,6 @@ class MultisampledTexture : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_MULTISAMPLED_TEXTURE_TYPE_H_ +#endif // SRC_TYPE_MULTISAMPLED_TEXTURE_TYPE_H_ diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/type/multisampled_texture_type_test.cc similarity index 78% rename from src/ast/type/multisampled_texture_type_test.cc rename to src/type/multisampled_texture_type_test.cc index 99bb0e5971..788d7df887 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/type/multisampled_texture_type_test.cc @@ -12,25 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/multisampled_texture_type.h" +#include "src/type/multisampled_texture_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -91,5 +90,4 @@ TEST_F(MultisampledTextureTest, MinBufferBindingSize) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/pointer_type.cc b/src/type/pointer_type.cc similarity index 85% rename from src/ast/type/pointer_type.cc rename to src/type/pointer_type.cc index 67c0cfaab5..5077d333f3 100644 --- a/src/ast/type/pointer_type.cc +++ b/src/type/pointer_type.cc @@ -12,18 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/pointer_type.h" +#include "src/type/pointer_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Pointer); +TINT_INSTANTIATE_CLASS_ID(tint::type::Pointer); namespace tint { -namespace ast { namespace type { -Pointer::Pointer(Type* subtype, StorageClass storage_class) +Pointer::Pointer(Type* subtype, ast::StorageClass storage_class) : subtype_(subtype), storage_class_(storage_class) {} std::string Pointer::type_name() const { @@ -41,5 +40,4 @@ Pointer* Pointer::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/pointer_type.h b/src/type/pointer_type.h similarity index 80% rename from src/ast/type/pointer_type.h rename to src/type/pointer_type.h index 7a9a61b4c8..bf64785796 100644 --- a/src/ast/type/pointer_type.h +++ b/src/type/pointer_type.h @@ -12,17 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_POINTER_TYPE_H_ -#define SRC_AST_TYPE_POINTER_TYPE_H_ +#ifndef SRC_TYPE_POINTER_TYPE_H_ +#define SRC_TYPE_POINTER_TYPE_H_ #include #include #include "src/ast/storage_class.h" -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A pointer type. @@ -31,7 +30,7 @@ class Pointer : public Castable { /// Construtor /// @param subtype the pointee type /// @param storage_class the storage class of the pointer - explicit Pointer(Type* subtype, StorageClass storage_class); + explicit Pointer(Type* subtype, ast::StorageClass storage_class); /// Move constructor Pointer(Pointer&&); ~Pointer() override; @@ -39,7 +38,7 @@ class Pointer : public Castable { /// @returns the pointee type Type* type() const { return subtype_; } /// @returns the storage class of the pointer - StorageClass storage_class() const { return storage_class_; } + ast::StorageClass storage_class() const { return storage_class_; } /// @returns the name for this type std::string type_name() const override; @@ -51,11 +50,10 @@ class Pointer : public Castable { private: Type* const subtype_; - StorageClass const storage_class_; + ast::StorageClass const storage_class_; }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_POINTER_TYPE_H_ +#endif // SRC_TYPE_POINTER_TYPE_H_ diff --git a/src/ast/type/pointer_type_test.cc b/src/type/pointer_type_test.cc similarity index 67% rename from src/ast/type/pointer_type_test.cc rename to src/type/pointer_type_test.cc index 95a4c87f3c..7b6c6a87a5 100644 --- a/src/ast/type/pointer_type_test.cc +++ b/src/type/pointer_type_test.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/pointer_type.h" +#include "src/type/pointer_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -35,14 +34,14 @@ using PointerTest = TestHelper; TEST_F(PointerTest, Creation) { I32 i32; - Pointer p{&i32, StorageClass::kStorage}; + Pointer p{&i32, ast::StorageClass::kStorage}; EXPECT_EQ(p.type(), &i32); - EXPECT_EQ(p.storage_class(), StorageClass::kStorage); + EXPECT_EQ(p.storage_class(), ast::StorageClass::kStorage); } TEST_F(PointerTest, Is) { I32 i32; - Pointer p{&i32, StorageClass::kFunction}; + Pointer p{&i32, ast::StorageClass::kFunction}; Type* ty = &p; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -61,11 +60,10 @@ TEST_F(PointerTest, Is) { TEST_F(PointerTest, TypeName) { I32 i32; - Pointer p{&i32, StorageClass::kWorkgroup}; + Pointer p{&i32, ast::StorageClass::kWorkgroup}; EXPECT_EQ(p.type_name(), "__ptr_workgroup__i32"); } } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/sampled_texture_type.cc b/src/type/sampled_texture_type.cc similarity index 90% rename from src/ast/type/sampled_texture_type.cc rename to src/type/sampled_texture_type.cc index 9a95c121a4..3d5d00a26e 100644 --- a/src/ast/type/sampled_texture_type.cc +++ b/src/type/sampled_texture_type.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/sampled_texture_type.h" +#include "src/type/sampled_texture_type.h" #include #include @@ -20,10 +20,9 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::SampledTexture); +TINT_INSTANTIATE_CLASS_ID(tint::type::SampledTexture); namespace tint { -namespace ast { namespace type { SampledTexture::SampledTexture(TextureDimension dim, Type* type) @@ -46,5 +45,4 @@ SampledTexture* SampledTexture::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/sampled_texture_type.h b/src/type/sampled_texture_type.h similarity index 87% rename from src/ast/type/sampled_texture_type.h rename to src/type/sampled_texture_type.h index cdc93fa6bb..32110506ca 100644 --- a/src/ast/type/sampled_texture_type.h +++ b/src/type/sampled_texture_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_SAMPLED_TEXTURE_TYPE_H_ -#define SRC_AST_TYPE_SAMPLED_TEXTURE_TYPE_H_ +#ifndef SRC_TYPE_SAMPLED_TEXTURE_TYPE_H_ +#define SRC_TYPE_SAMPLED_TEXTURE_TYPE_H_ #include -#include "src/ast/type/texture_type.h" +#include "src/type/texture_type.h" namespace tint { -namespace ast { namespace type { /// A sampled texture type. @@ -50,7 +49,6 @@ class SampledTexture : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_SAMPLED_TEXTURE_TYPE_H_ +#endif // SRC_TYPE_SAMPLED_TEXTURE_TYPE_H_ diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/type/sampled_texture_type_test.cc similarity index 78% rename from src/ast/type/sampled_texture_type_test.cc rename to src/type/sampled_texture_type_test.cc index 5c6bcb4493..a80312f7ba 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/type/sampled_texture_type_test.cc @@ -12,24 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/sampled_texture_type.h" +#include "src/type/sampled_texture_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -89,5 +88,4 @@ TEST_F(SampledTextureTest, MinBufferBindingSize) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/sampler_type.cc b/src/type/sampler_type.cc similarity index 91% rename from src/ast/type/sampler_type.cc rename to src/type/sampler_type.cc index f1070d468a..d4b0ae7021 100644 --- a/src/ast/type/sampler_type.cc +++ b/src/type/sampler_type.cc @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/sampler_type.h" +#include "src/type/sampler_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Sampler); +TINT_INSTANTIATE_CLASS_ID(tint::type::Sampler); namespace tint { -namespace ast { namespace type { std::ostream& operator<<(std::ostream& out, SamplerKind kind) { @@ -51,5 +50,4 @@ Sampler* Sampler::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/sampler_type.h b/src/type/sampler_type.h similarity index 90% rename from src/ast/type/sampler_type.h rename to src/type/sampler_type.h index 28a60e8faf..8c71128852 100644 --- a/src/ast/type/sampler_type.h +++ b/src/type/sampler_type.h @@ -12,16 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_SAMPLER_TYPE_H_ -#define SRC_AST_TYPE_SAMPLER_TYPE_H_ +#ifndef SRC_TYPE_SAMPLER_TYPE_H_ +#define SRC_TYPE_SAMPLER_TYPE_H_ #include #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// The different kinds of samplers @@ -62,7 +61,6 @@ class Sampler : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_SAMPLER_TYPE_H_ +#endif // SRC_TYPE_SAMPLER_TYPE_H_ diff --git a/src/ast/type/sampler_type_test.cc b/src/type/sampler_type_test.cc similarity index 79% rename from src/ast/type/sampler_type_test.cc rename to src/type/sampler_type_test.cc index 9641aecfff..2648300349 100644 --- a/src/ast/type/sampler_type_test.cc +++ b/src/type/sampler_type_test.cc @@ -12,23 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/sampler_type.h" +#include "src/type/sampler_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -80,5 +79,4 @@ TEST_F(SamplerTest, MinBufferBindingSize) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/storage_texture_type.cc b/src/type/storage_texture_type.cc similarity index 96% rename from src/ast/type/storage_texture_type.cc rename to src/type/storage_texture_type.cc index 3dc432ce34..1f175fd872 100644 --- a/src/ast/type/storage_texture_type.cc +++ b/src/type/storage_texture_type.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/storage_texture_type.h" +#include "src/type/storage_texture_type.h" #include #include @@ -20,10 +20,9 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::StorageTexture); +TINT_INSTANTIATE_CLASS_ID(tint::type::StorageTexture); namespace tint { -namespace ast { namespace type { // Note, these names match the names in the WGSL spec. This behaviour is used @@ -168,5 +167,4 @@ StorageTexture* StorageTexture::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/storage_texture_type.h b/src/type/storage_texture_type.h similarity index 88% rename from src/ast/type/storage_texture_type.h rename to src/type/storage_texture_type.h index 2723a0f558..51b147e276 100644 --- a/src/ast/type/storage_texture_type.h +++ b/src/type/storage_texture_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_STORAGE_TEXTURE_TYPE_H_ -#define SRC_AST_TYPE_STORAGE_TEXTURE_TYPE_H_ +#ifndef SRC_TYPE_STORAGE_TEXTURE_TYPE_H_ +#define SRC_TYPE_STORAGE_TEXTURE_TYPE_H_ #include -#include "src/ast/type/texture_type.h" +#include "src/type/texture_type.h" namespace tint { -namespace ast { namespace type { /// The image format in the storage texture @@ -70,8 +69,7 @@ class StorageTexture : public Castable { /// Constructor /// @param dim the dimensionality of the texture /// @param format the image format of the texture - StorageTexture(TextureDimension dim, - ImageFormat format); + StorageTexture(TextureDimension dim, ImageFormat format); /// Move constructor StorageTexture(StorageTexture&&); @@ -101,7 +99,6 @@ class StorageTexture : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_STORAGE_TEXTURE_TYPE_H_ +#endif // SRC_TYPE_STORAGE_TEXTURE_TYPE_H_ diff --git a/src/ast/type/storage_texture_type_test.cc b/src/type/storage_texture_type_test.cc similarity index 85% rename from src/ast/type/storage_texture_type_test.cc rename to src/type/storage_texture_type_test.cc index d05d53d823..7b327da33a 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/type/storage_texture_type_test.cc @@ -12,28 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/storage_texture_type.h" +#include "src/type/storage_texture_type.h" #include #include "src/ast/identifier_expression.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" namespace tint { -namespace ast { namespace type { namespace { @@ -120,5 +119,4 @@ TEST_F(StorageTextureTest, MinBufferBindingSize) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/struct_type.cc b/src/type/struct_type.cc similarity index 89% rename from src/ast/type/struct_type.cc rename to src/type/struct_type.cc index 24f5640bdf..39d65db2bb 100644 --- a/src/ast/type/struct_type.cc +++ b/src/type/struct_type.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" #include #include #include "src/ast/clone_context.h" #include "src/ast/module.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/matrix_type.h" +#include "src/type/vector_type.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Struct); +TINT_INSTANTIATE_CLASS_ID(tint::type::Struct); namespace tint { -namespace ast { namespace type { Struct::Struct(const Symbol& sym, ast::Struct* impl) @@ -88,5 +87,4 @@ Struct* Struct::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/struct_type.h b/src/type/struct_type.h similarity index 92% rename from src/ast/type/struct_type.h rename to src/type/struct_type.h index e340f4bbc3..63fcaa2721 100644 --- a/src/ast/type/struct_type.h +++ b/src/type/struct_type.h @@ -12,18 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_STRUCT_TYPE_H_ -#define SRC_AST_TYPE_STRUCT_TYPE_H_ +#ifndef SRC_TYPE_STRUCT_TYPE_H_ +#define SRC_TYPE_STRUCT_TYPE_H_ #include #include #include "src/ast/struct.h" -#include "src/ast/type/type.h" #include "src/symbol.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A structure type @@ -72,7 +71,6 @@ class Struct : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_STRUCT_TYPE_H_ +#endif // SRC_TYPE_STRUCT_TYPE_H_ diff --git a/src/ast/type/struct_type_test.cc b/src/type/struct_type_test.cc similarity index 51% rename from src/ast/type/struct_type_test.cc rename to src/type/struct_type_test.cc index ca5be2814f..2ed78a1f82 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/type/struct_type_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" #include @@ -20,34 +20,35 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { -using StructTest = TestHelper; +using StructTypeTest = TestHelper; -TEST_F(StructTest, Creation) { - auto* impl = create(StructMemberList{}, StructDecorationList{}); +TEST_F(StructTypeTest, Creation) { + auto* impl = + create(ast::StructMemberList{}, ast::StructDecorationList{}); auto* ptr = impl; auto* s = ty.struct_("S", impl); EXPECT_EQ(s->impl(), ptr); } -TEST_F(StructTest, Is) { - auto* impl = create(StructMemberList{}, StructDecorationList{}); +TEST_F(StructTypeTest, Is) { + auto* impl = + create(ast::StructMemberList{}, ast::StructDecorationList{}); auto* s = ty.struct_("S", impl); type::Type* ty = s; EXPECT_FALSE(ty->Is()); @@ -65,140 +66,145 @@ TEST_F(StructTest, Is) { EXPECT_FALSE(ty->Is()); } -TEST_F(StructTest, TypeName) { - auto* impl = create(StructMemberList{}, StructDecorationList{}); +TEST_F(StructTypeTest, TypeName) { + auto* impl = + create(ast::StructMemberList{}, ast::StructDecorationList{}); auto* s = ty.struct_("my_struct", impl); EXPECT_EQ(s->type_name(), "__struct_tint_symbol_1"); } -TEST_F(StructTest, MinBufferBindingSize) { +TEST_F(StructTypeTest, MinBufferBindingSize) { auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, MinBufferBindingSizeArray) { - Array arr(ty.u32, 4, ArrayDecorationList{create(4)}); +TEST_F(StructTypeTest, MinBufferBindingSizeArray) { + Array arr(ty.u32, 4, + ast::ArrayDecorationList{create(4)}); auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)}), - Member("bar", &arr, {MemberOffset(8)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)}), + Member("bar", &arr, {MemberOffset(8)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(32u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(24u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, MinBufferBindingSizeRuntimeArray) { - Array arr(ty.u32, 0, ArrayDecorationList{create(4)}); +TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) { + Array arr(ty.u32, 0, + ast::ArrayDecorationList{create(4)}); auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)}), - Member("bar", ty.u32, {MemberOffset(8)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)}), + Member("bar", ty.u32, {MemberOffset(8)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(12u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, MinBufferBindingSizeVec2) { +TEST_F(StructTypeTest, MinBufferBindingSizeVec2) { auto* str = create( - StructMemberList{Member("foo", ty.vec2(), {MemberOffset(0)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.vec2(), {MemberOffset(0)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, MinBufferBindingSizeVec3) { +TEST_F(StructTypeTest, MinBufferBindingSizeVec3) { auto* str = create( - StructMemberList{Member("foo", ty.vec3(), {MemberOffset(0)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.vec3(), {MemberOffset(0)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, MinBufferBindingSizeVec4) { +TEST_F(StructTypeTest, MinBufferBindingSizeVec4) { auto* str = create( - StructMemberList{Member("foo", ty.vec4(), {MemberOffset(0)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.vec4(), {MemberOffset(0)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, BaseAlignment) { +TEST_F(StructTypeTest, BaseAlignment) { auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(8)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(8)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, BaseAlignmentArray) { - Array arr(ty.u32, 4, ArrayDecorationList{create(4)}); +TEST_F(StructTypeTest, BaseAlignmentArray) { + Array arr(ty.u32, 4, + ast::ArrayDecorationList{create(4)}); auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)}), - Member("bar", &arr, {MemberOffset(8)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)}), + Member("bar", &arr, {MemberOffset(8)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, BaseAlignmentRuntimeArray) { - Array arr(ty.u32, 0, ArrayDecorationList{create(4)}); +TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) { + Array arr(ty.u32, 0, + ast::ArrayDecorationList{create(4)}); auto* str = create( - StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), - Member("bar", ty.u32, {MemberOffset(4)}), - Member("bar", ty.u32, {MemberOffset(8)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.u32, {MemberOffset(0)}), + Member("bar", ty.u32, {MemberOffset(4)}), + Member("bar", ty.u32, {MemberOffset(8)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(4u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, BaseAlignmentVec2) { +TEST_F(StructTypeTest, BaseAlignmentVec2) { auto* str = create( - StructMemberList{Member("foo", ty.vec2(), {MemberOffset(0)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.vec2(), {MemberOffset(0)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, BaseAlignmentVec3) { +TEST_F(StructTypeTest, BaseAlignmentVec3) { auto* str = create( - StructMemberList{Member("foo", ty.vec3(), {MemberOffset(0)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.vec3(), {MemberOffset(0)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kStorageBuffer)); } -TEST_F(StructTest, BaseAlignmentVec4) { +TEST_F(StructTypeTest, BaseAlignmentVec4) { auto* str = create( - StructMemberList{Member("foo", ty.vec4(), {MemberOffset(0)})}, - StructDecorationList{}); + ast::StructMemberList{Member("foo", ty.vec4(), {MemberOffset(0)})}, + ast::StructDecorationList{}); auto* s_ty = ty.struct_("s_ty", str); EXPECT_EQ(16u, s_ty->BaseAlignment(MemoryLayout::kUniformBuffer)); @@ -207,5 +213,4 @@ TEST_F(StructTest, BaseAlignmentVec4) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/type/test_helper.h b/src/type/test_helper.h new file mode 100644 index 0000000000..e161d04ece --- /dev/null +++ b/src/type/test_helper.h @@ -0,0 +1,52 @@ +// 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. + +#ifndef SRC_TYPE_TEST_HELPER_H_ +#define SRC_TYPE_TEST_HELPER_H_ + +#include +#include +#include + +#include "gtest/gtest.h" +#include "src/ast/builder.h" +#include "src/ast/module.h" +#include "src/demangler.h" + +namespace tint { +namespace type { + +/// Helper class for testing +template +class TestHelperBase : public BASE, public ast::BuilderWithModule { + public: + /// Demangles the given string + /// @param s the string to demangle + /// @returns the demangled string + std::string demangle(const std::string& s) { + return demanger.Demangle(*mod, s); + } + + /// A demangler + Demangler demanger; +}; +using TestHelper = TestHelperBase; + +template +using TestParamHelper = TestHelperBase>; + +} // namespace type +} // namespace tint + +#endif // SRC_TYPE_TEST_HELPER_H_ diff --git a/src/ast/type/texture_type.cc b/src/type/texture_type.cc similarity index 91% rename from src/ast/type/texture_type.cc rename to src/type/texture_type.cc index 58a0d47f0f..c55c599fec 100644 --- a/src/ast/type/texture_type.cc +++ b/src/type/texture_type.cc @@ -12,18 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/texture_type.h" +#include "src/type/texture_type.h" #include #include -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Texture); +TINT_INSTANTIATE_CLASS_ID(tint::type::Texture); namespace tint { -namespace ast { namespace type { std::ostream& operator<<(std::ostream& out, TextureDimension dim) { @@ -97,5 +96,4 @@ Texture::Texture(Texture&&) = default; Texture::~Texture() = default; } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/texture_type.h b/src/type/texture_type.h similarity index 91% rename from src/ast/type/texture_type.h rename to src/type/texture_type.h index 495afd95a2..32ea8a01f6 100644 --- a/src/ast/type/texture_type.h +++ b/src/type/texture_type.h @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_TEXTURE_TYPE_H_ -#define SRC_AST_TYPE_TEXTURE_TYPE_H_ +#ifndef SRC_TYPE_TEXTURE_TYPE_H_ +#define SRC_TYPE_TEXTURE_TYPE_H_ -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// The dimensionality of the texture @@ -73,7 +72,6 @@ class Texture : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_TEXTURE_TYPE_H_ +#endif // SRC_TYPE_TEXTURE_TYPE_H_ diff --git a/src/ast/type/texture_type_test.cc b/src/type/texture_type_test.cc similarity index 94% rename from src/ast/type/texture_type_test.cc rename to src/type/texture_type_test.cc index 3ed1921964..33a2c433db 100644 --- a/src/ast/type/texture_type_test.cc +++ b/src/type/texture_type_test.cc @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/texture_type.h" +#include "src/type/texture_type.h" -#include "src/ast/test_helper.h" +#include "src/type/test_helper.h" namespace tint { -namespace ast { namespace type { namespace { @@ -47,5 +46,4 @@ TEST_F(TextureTypeTest, NumCoordinateAxes) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/type.cc b/src/type/type.cc similarity index 79% rename from src/ast/type/type.cc rename to src/type/type.cc index 329812f82a..623d07616c 100644 --- a/src/ast/type/type.cc +++ b/src/type/type.cc @@ -12,29 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/type.h" +#include "src/type/type.h" #include -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/access_control_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampler_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Type); +TINT_INSTANTIATE_CLASS_ID(tint::type::Type); namespace tint { -namespace ast { namespace type { Type::Type() = default; @@ -121,5 +120,4 @@ bool Type::is_integer_scalar_or_vector() { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/type.h b/src/type/type.h similarity index 94% rename from src/ast/type/type.h rename to src/type/type.h index 536ddd1370..adbd9a1d73 100644 --- a/src/ast/type/type.h +++ b/src/type/type.h @@ -12,21 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_TYPE_H_ -#define SRC_AST_TYPE_TYPE_H_ +#ifndef SRC_TYPE_TYPE_H_ +#define SRC_TYPE_TYPE_H_ #include #include "src/castable.h" namespace tint { -namespace ast { +namespace ast { class Module; class CloneContext; +} // namespace ast namespace type { +using CloneContext = ast::CloneContext; // TEMP + /// Supported memory layouts for calculating sizes enum class MemoryLayout { kUniformBuffer, kStorageBuffer }; @@ -40,7 +43,7 @@ class Type : public Castable { /// Clones this type and all transitive types using the `CloneContext` `ctx`. /// @param ctx the clone context /// @return the newly cloned type - virtual Type* Clone(CloneContext* ctx) const = 0; + virtual Type* Clone(ast::CloneContext* ctx) const = 0; /// @returns the name for this type. The type name is unique over all types. virtual std::string type_name() const = 0; @@ -105,13 +108,12 @@ class Type : public Castable { /// @param t the `Type` to clone (if not null) /// @return the cloned type template - static T* Clone(Module* m, const T* t) { + static T* Clone(ast::Module* m, const T* t) { return (t != nullptr) ? static_cast(t->Clone(m)) : nullptr; } }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_TYPE_H_ +#endif // SRC_TYPE_TYPE_H_ diff --git a/src/ast/type_manager.cc b/src/type/type_manager.cc similarity index 70% rename from src/ast/type_manager.cc rename to src/type/type_manager.cc index 39f4e07f19..235819fdee 100644 --- a/src/ast/type_manager.cc +++ b/src/type/type_manager.cc @@ -12,23 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type_manager.h" +#include "src/type/type_manager.h" #include namespace tint { -namespace ast { +namespace type { -TypeManager::TypeManager() = default; -TypeManager::TypeManager(TypeManager&&) = default; -TypeManager& TypeManager::operator=(TypeManager&& rhs) = default; -TypeManager::~TypeManager() = default; +Manager::Manager() = default; +Manager::Manager(Manager&&) = default; +Manager& Manager::operator=(Manager&& rhs) = default; +Manager::~Manager() = default; -void TypeManager::Reset() { +void Manager::Reset() { types_.clear(); } -type::Type* TypeManager::Get(std::unique_ptr type) { +type::Type* Manager::Get(std::unique_ptr type) { auto name = type->type_name(); if (types_.find(name) == types_.end()) { @@ -37,5 +37,5 @@ type::Type* TypeManager::Get(std::unique_ptr type) { return types_.find(name)->second.get(); } -} // namespace ast +} // namespace type } // namespace tint diff --git a/src/ast/type_manager.h b/src/type/type_manager.h similarity index 82% rename from src/ast/type_manager.h rename to src/type/type_manager.h index f428ac98f5..5e2835541d 100644 --- a/src/ast/type_manager.h +++ b/src/type/type_manager.h @@ -12,35 +12,35 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_MANAGER_H_ -#define SRC_AST_TYPE_MANAGER_H_ +#ifndef SRC_TYPE_TYPE_MANAGER_H_ +#define SRC_TYPE_TYPE_MANAGER_H_ #include #include #include #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { +namespace type { /// The type manager holds all the pointers to the known types. -class TypeManager { +class Manager { public: /// Constructor - TypeManager(); + Manager(); /// Move constructor - TypeManager(TypeManager&&); + Manager(Manager&&); /// Move assignment operator - /// @param rhs the TypeManager to move - /// @return this TypeManager - TypeManager& operator=(TypeManager&& rhs); + /// @param rhs the Manager to move + /// @return this Manager + Manager& operator=(Manager&& rhs); /// Destructor - ~TypeManager(); + ~Manager(); /// Clears all registered types. void Reset(); @@ -69,7 +69,7 @@ class TypeManager { std::unordered_map> types_; }; -} // namespace ast +} // namespace type } // namespace tint -#endif // SRC_AST_TYPE_MANAGER_H_ +#endif // SRC_TYPE_TYPE_MANAGER_H_ diff --git a/src/ast/type_manager_test.cc b/src/type/type_manager_test.cc similarity index 62% rename from src/ast/type_manager_test.cc rename to src/type/type_manager_test.cc index f78a61f132..d8cf49546b 100644 --- a/src/ast/type_manager_test.cc +++ b/src/type/type_manager_test.cc @@ -12,61 +12,60 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type_manager.h" +#include "src/type/type_manager.h" #include "gtest/gtest.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" namespace tint { -namespace ast { +namespace type { namespace { using TypeManagerTest = testing::Test; TEST_F(TypeManagerTest, GetUnregistered) { - TypeManager tm; - auto* t = tm.Get(std::make_unique()); + Manager tm; + auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); - EXPECT_TRUE(t->Is()); + EXPECT_TRUE(t->Is()); } TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) { - TypeManager tm; - auto* t = tm.Get(std::make_unique()); + Manager tm; + auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); - EXPECT_TRUE(t->Is()); + EXPECT_TRUE(t->Is()); - auto* t2 = tm.Get(std::make_unique()); + auto* t2 = tm.Get(std::make_unique()); EXPECT_EQ(t, t2); } TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) { - TypeManager tm; - auto* t = tm.Get(std::make_unique()); + Manager tm; + auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); - EXPECT_TRUE(t->Is()); + EXPECT_TRUE(t->Is()); - auto* t2 = tm.Get(std::make_unique()); + auto* t2 = tm.Get(std::make_unique()); ASSERT_NE(t2, nullptr); EXPECT_NE(t, t2); - EXPECT_TRUE(t2->Is()); + EXPECT_TRUE(t2->Is()); } TEST_F(TypeManagerTest, ResetClearsPreviousData) { - TypeManager tm; - auto* t = tm.Get(std::make_unique()); + Manager tm; + auto* t = tm.Get(std::make_unique()); ASSERT_NE(t, nullptr); EXPECT_FALSE(tm.types().empty()); tm.Reset(); EXPECT_TRUE(tm.types().empty()); - auto* t2 = tm.Get(std::make_unique()); + auto* t2 = tm.Get(std::make_unique()); ASSERT_NE(t2, nullptr); } } // namespace -} // namespace ast +} // namespace type } // namespace tint diff --git a/src/ast/type/u32_type.cc b/src/type/u32_type.cc similarity index 90% rename from src/ast/type/u32_type.cc rename to src/type/u32_type.cc index 37364d7b30..fd87b36a2b 100644 --- a/src/ast/type/u32_type.cc +++ b/src/type/u32_type.cc @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/u32_type.h" +#include "src/type/u32_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::U32); +TINT_INSTANTIATE_CLASS_ID(tint::type::U32); namespace tint { -namespace ast { namespace type { U32::U32() = default; @@ -46,5 +45,4 @@ U32* U32::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/u32_type.h b/src/type/u32_type.h similarity index 90% rename from src/ast/type/u32_type.h rename to src/type/u32_type.h index 9e041556cb..77d1eda9af 100644 --- a/src/ast/type/u32_type.h +++ b/src/type/u32_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_U32_TYPE_H_ -#define SRC_AST_TYPE_U32_TYPE_H_ +#ifndef SRC_TYPE_U32_TYPE_H_ +#define SRC_TYPE_U32_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A unsigned int 32 type. @@ -52,7 +51,6 @@ class U32 : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_U32_TYPE_H_ +#endif // SRC_TYPE_U32_TYPE_H_ diff --git a/src/ast/type/u32_type_test.cc b/src/type/u32_type_test.cc similarity index 74% rename from src/ast/type/u32_type_test.cc rename to src/type/u32_type_test.cc index bf3a56b3d1..e0390ce785 100644 --- a/src/ast/type/u32_type_test.cc +++ b/src/type/u32_type_test.cc @@ -12,23 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/u32_type.h" +#include "src/type/u32_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampler_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/vector_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -69,5 +68,4 @@ TEST_F(U32Test, BaseAlignment) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/vector_type.cc b/src/type/vector_type.cc similarity index 92% rename from src/ast/type/vector_type.cc rename to src/type/vector_type.cc index 3697e4e286..b56273b622 100644 --- a/src/ast/type/vector_type.cc +++ b/src/type/vector_type.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/vector_type.h" +#include "src/type/vector_type.h" #include #include @@ -20,10 +20,9 @@ #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Vector); +TINT_INSTANTIATE_CLASS_ID(tint::type::Vector); namespace tint { -namespace ast { namespace type { Vector::Vector(Type* subtype, uint32_t size) : subtype_(subtype), size_(size) { @@ -58,5 +57,4 @@ Vector* Vector::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/vector_type.h b/src/type/vector_type.h similarity index 91% rename from src/ast/type/vector_type.h rename to src/type/vector_type.h index 4228c59a06..e9f1af5113 100644 --- a/src/ast/type/vector_type.h +++ b/src/type/vector_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_VECTOR_TYPE_H_ -#define SRC_AST_TYPE_VECTOR_TYPE_H_ +#ifndef SRC_TYPE_VECTOR_TYPE_H_ +#define SRC_TYPE_VECTOR_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A vector type. @@ -63,7 +62,6 @@ class Vector : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_VECTOR_TYPE_H_ +#endif // SRC_TYPE_VECTOR_TYPE_H_ diff --git a/src/ast/type/vector_type_test.cc b/src/type/vector_type_test.cc similarity index 82% rename from src/ast/type/vector_type_test.cc rename to src/type/vector_type_test.cc index 9b885ae32d..20656d763b 100644 --- a/src/ast/type/vector_type_test.cc +++ b/src/type/vector_type_test.cc @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/vector_type.h" +#include "src/type/vector_type.h" -#include "src/ast/test_helper.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/test_helper.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" namespace tint { -namespace ast { namespace type { namespace { @@ -103,5 +102,4 @@ TEST_F(VectorTest, BaseAlignmentVec4) { } // namespace } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/void_type.cc b/src/type/void_type.cc similarity index 88% rename from src/ast/type/void_type.cc rename to src/type/void_type.cc index 62ce40297e..aa894a5b10 100644 --- a/src/ast/type/void_type.cc +++ b/src/type/void_type.cc @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/type/void_type.h" +#include "src/type/void_type.h" #include "src/ast/clone_context.h" #include "src/ast/module.h" -TINT_INSTANTIATE_CLASS_ID(tint::ast::type::Void); +TINT_INSTANTIATE_CLASS_ID(tint::type::Void); namespace tint { -namespace ast { namespace type { Void::Void() = default; @@ -38,5 +37,4 @@ Void* Void::Clone(CloneContext* ctx) const { } } // namespace type -} // namespace ast } // namespace tint diff --git a/src/ast/type/void_type.h b/src/type/void_type.h similarity index 86% rename from src/ast/type/void_type.h rename to src/type/void_type.h index 8631188156..1207808cfb 100644 --- a/src/ast/type/void_type.h +++ b/src/type/void_type.h @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TYPE_VOID_TYPE_H_ -#define SRC_AST_TYPE_VOID_TYPE_H_ +#ifndef SRC_TYPE_VOID_TYPE_H_ +#define SRC_TYPE_VOID_TYPE_H_ #include -#include "src/ast/type/type.h" +#include "src/type/type.h" namespace tint { -namespace ast { namespace type { /// A void type @@ -42,7 +41,6 @@ class Void : public Castable { }; } // namespace type -} // namespace ast } // namespace tint -#endif // SRC_AST_TYPE_VOID_TYPE_H_ +#endif // SRC_TYPE_VOID_TYPE_H_ diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 70192025a9..6dcce00a8f 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -38,24 +38,24 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { @@ -89,10 +89,10 @@ void TypeDeterminer::set_referenced_from_function_if_needed(ast::Variable* var, } bool TypeDeterminer::Determine() { - std::vector storage_textures; + std::vector storage_textures; for (auto& it : mod_->types()) { if (auto* storage = - it.second->UnwrapIfNeeded()->As()) { + it.second->UnwrapIfNeeded()->As()) { storage_textures.emplace_back(storage); } } @@ -334,13 +334,13 @@ bool TypeDeterminer::DetermineArrayAccessor( auto* res = expr->array()->result_type(); auto* parent_type = res->UnwrapAll(); - ast::type::Type* ret = nullptr; - if (auto* arr = parent_type->As()) { + type::Type* ret = nullptr; + if (auto* arr = parent_type->As()) { ret = arr->type(); - } else if (auto* vec = parent_type->As()) { + } else if (auto* vec = parent_type->As()) { ret = vec->type(); - } else if (auto* mat = parent_type->As()) { - ret = mod_->create(mat->type(), mat->rows()); + } else if (auto* mat = parent_type->As()) { + ret = mod_->create(mat->type(), mat->rows()); } else { set_error(expr->source(), "invalid parent type (" + parent_type->type_name() + @@ -349,14 +349,14 @@ bool TypeDeterminer::DetermineArrayAccessor( } // If we're extracting from a pointer, we return a pointer. - if (auto* ptr = res->As()) { - ret = mod_->create(ret, ptr->storage_class()); - } else if (auto* arr = parent_type->As()) { + if (auto* ptr = res->As()) { + ret = mod_->create(ret, ptr->storage_class()); + } else if (auto* arr = parent_type->As()) { if (!arr->type()->is_scalar()) { // If we extract a non-scalar from an array then we also get a pointer. We // will generate a Function storage class variable to store this // into. - ret = mod_->create(ret, ast::StorageClass::kFunction); + ret = mod_->create(ret, ast::StorageClass::kFunction); } } expr->set_result_type(ret); @@ -520,11 +520,11 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, } if (ident->intrinsic() == ast::Intrinsic::kAny || ident->intrinsic() == ast::Intrinsic::kAll) { - expr->func()->set_result_type(mod_->create()); + expr->func()->set_result_type(mod_->create()); return true; } if (ident->intrinsic() == ast::Intrinsic::kArrayLength) { - expr->func()->set_result_type(mod_->create()); + expr->func()->set_result_type(mod_->create()); return true; } if (ast::intrinsic::IsFloatClassificationIntrinsic(ident->intrinsic())) { @@ -534,12 +534,12 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, return false; } - auto* bool_type = mod_->create(); + auto* bool_type = mod_->create(); auto* param_type = expr->params()[0]->result_type()->UnwrapPtrIfNeeded(); - if (auto* vec = param_type->As()) { + if (auto* vec = param_type->As()) { expr->func()->set_result_type( - mod_->create(bool_type, vec->size())); + mod_->create(bool_type, vec->size())); } else { expr->func()->set_result_type(bool_type); } @@ -549,16 +549,16 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, ast::intrinsic::TextureSignature::Parameters param; auto* texture_param = expr->params()[0]; - if (!texture_param->result_type()->UnwrapAll()->Is()) { + if (!texture_param->result_type()->UnwrapAll()->Is()) { set_error(expr->source(), "invalid first argument for " + mod_->SymbolToName(ident->symbol())); return false; } - ast::type::Texture* texture = - texture_param->result_type()->UnwrapAll()->As(); + type::Texture* texture = + texture_param->result_type()->UnwrapAll()->As(); - bool is_array = ast::type::IsTextureArray(texture->dim()); - bool is_multisampled = texture->Is(); + bool is_array = type::IsTextureArray(texture->dim()); + bool is_multisampled = texture->Is(); switch (ident->intrinsic()) { case ast::Intrinsic::kTextureDimensions: param.idx.texture = param.count++; @@ -673,26 +673,26 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, std::make_unique(param)); // Set the function return type - ast::type::Type* return_type = nullptr; + type::Type* return_type = nullptr; switch (ident->intrinsic()) { case ast::Intrinsic::kTextureDimensions: { - auto* i32 = mod_->create(); + auto* i32 = mod_->create(); switch (texture->dim()) { default: set_error(expr->source(), "invalid texture dimensions"); break; - case ast::type::TextureDimension::k1d: - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1d: + case type::TextureDimension::k1dArray: return_type = i32; break; - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::k2dArray: - return_type = mod_->create(i32, 2); + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + return_type = mod_->create(i32, 2); break; - case ast::type::TextureDimension::k3d: - case ast::type::TextureDimension::kCube: - case ast::type::TextureDimension::kCubeArray: - return_type = mod_->create(i32, 3); + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: + return_type = mod_->create(i32, 3); break; } break; @@ -700,29 +700,29 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, case ast::Intrinsic::kTextureNumLayers: case ast::Intrinsic::kTextureNumLevels: case ast::Intrinsic::kTextureNumSamples: - return_type = mod_->create(); + return_type = mod_->create(); break; case ast::Intrinsic::kTextureStore: - return_type = mod_->create(); + return_type = mod_->create(); break; default: { - if (texture->Is()) { - return_type = mod_->create(); + if (texture->Is()) { + return_type = mod_->create(); } else { - ast::type::Type* type = nullptr; - if (auto* storage = texture->As()) { + type::Type* type = nullptr; + if (auto* storage = texture->As()) { type = storage->type(); - } else if (auto* sampled = texture->As()) { + } else if (auto* sampled = texture->As()) { type = sampled->type(); } else if (auto* msampled = - texture->As()) { + texture->As()) { type = msampled->type(); } else { set_error(expr->source(), "unknown texture type for texture sampling"); return false; } - return_type = mod_->create(type, 4); + return_type = mod_->create(type, 4); } } } @@ -731,7 +731,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, return true; } if (ident->intrinsic() == ast::Intrinsic::kDot) { - expr->func()->set_result_type(mod_->create()); + expr->func()->set_result_type(mod_->create()); return true; } if (ident->intrinsic() == ast::Intrinsic::kSelect) { @@ -770,7 +770,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, return false; } - std::vector result_types; + std::vector result_types; for (uint32_t i = 0; i < data->param_count; ++i) { result_types.push_back( expr->params()[i]->result_type()->UnwrapPtrIfNeeded()); @@ -813,7 +813,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, return false; } if (data->vector_size > 0 && - result_types.back()->As()->size() != + result_types.back()->As()->size() != data->vector_size) { set_error(expr->source(), "incorrect vector size for " + mod_->SymbolToName(ident->symbol()) + @@ -824,7 +824,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, } break; case IntrinsicDataType::kMatrix: - if (!result_types.back()->Is()) { + if (!result_types.back()->Is()) { set_error(expr->source(), "incorrect type for " + mod_->SymbolToName(ident->symbol()) + ". Requires matrix value"); @@ -850,13 +850,12 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, expr->func()->set_result_type( result_types[0]->is_float_scalar() ? result_types[0] - : result_types[0]->As()->type()); + : result_types[0]->As()->type()); return true; } // The determinant returns the component type of the columns if (ident->intrinsic() == ast::Intrinsic::kDeterminant) { - expr->func()->set_result_type( - result_types[0]->As()->type()); + expr->func()->set_result_type(result_types[0]->As()->type()); return true; } expr->func()->set_result_type(result_types[0]); @@ -886,11 +885,11 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) { // the pointer around the variable type. if (var->is_const()) { expr->set_result_type(var->type()); - } else if (var->type()->Is()) { + } else if (var->type()->Is()) { expr->set_result_type(var->type()); } else { expr->set_result_type( - mod_->create(var->type(), var->storage_class())); + mod_->create(var->type(), var->storage_class())); } set_referenced_from_function_if_needed(var, true); @@ -1073,8 +1072,8 @@ bool TypeDeterminer::DetermineMemberAccessor( auto* res = expr->structure()->result_type(); auto* data_type = res->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); - ast::type::Type* ret = nullptr; - if (auto* ty = data_type->As()) { + type::Type* ret = nullptr; + if (auto* ty = data_type->As()) { auto* strct = ty->impl(); auto symbol = expr->member()->symbol(); @@ -1092,10 +1091,10 @@ bool TypeDeterminer::DetermineMemberAccessor( } // If we're extracting from a pointer, we return a pointer. - if (auto* ptr = res->As()) { - ret = mod_->create(ret, ptr->storage_class()); + if (auto* ptr = res->As()) { + ret = mod_->create(ret, ptr->storage_class()); } - } else if (auto* vec = data_type->As()) { + } else if (auto* vec = data_type->As()) { // TODO(dsinclair): Swizzle, record into the identifier experesion auto size = mod_->SymbolToName(expr->member()->symbol()).size(); @@ -1103,14 +1102,14 @@ bool TypeDeterminer::DetermineMemberAccessor( // A single element swizzle is just the type of the vector. ret = vec->type(); // If we're extracting from a pointer, we return a pointer. - if (auto* ptr = res->As()) { - ret = mod_->create(ret, ptr->storage_class()); + if (auto* ptr = res->As()) { + ret = mod_->create(ret, ptr->storage_class()); } } else { // The vector will have a number of components equal to the length of the // swizzle. This assumes the validator will check that the swizzle // is correct. - ret = mod_->create(vec->type(), size); + ret = mod_->create(vec->type(), size); } } else { set_error( @@ -1141,11 +1140,10 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) { if (expr->IsLogicalAnd() || expr->IsLogicalOr() || expr->IsEqual() || expr->IsNotEqual() || expr->IsLessThan() || expr->IsGreaterThan() || expr->IsLessThanEqual() || expr->IsGreaterThanEqual()) { - auto* bool_type = mod_->create(); + auto* bool_type = mod_->create(); auto* param_type = expr->lhs()->result_type()->UnwrapPtrIfNeeded(); - if (auto* vec = param_type->As()) { - expr->set_result_type( - mod_->create(bool_type, vec->size())); + if (auto* vec = param_type->As()) { + expr->set_result_type(mod_->create(bool_type, vec->size())); } else { expr->set_result_type(bool_type); } @@ -1157,19 +1155,19 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) { // Note, the ordering here matters. The later checks depend on the prior // checks having been done. - auto* lhs_mat = lhs_type->As(); - auto* rhs_mat = rhs_type->As(); - auto* lhs_vec = lhs_type->As(); - auto* rhs_vec = rhs_type->As(); + auto* lhs_mat = lhs_type->As(); + auto* rhs_mat = rhs_type->As(); + auto* lhs_vec = lhs_type->As(); + auto* rhs_vec = rhs_type->As(); if (lhs_mat && rhs_mat) { - expr->set_result_type(mod_->create( + expr->set_result_type(mod_->create( lhs_mat->type(), lhs_mat->rows(), rhs_mat->columns())); } else if (lhs_mat && rhs_vec) { expr->set_result_type( - mod_->create(lhs_mat->type(), lhs_mat->rows())); + mod_->create(lhs_mat->type(), lhs_mat->rows())); } else if (lhs_vec && rhs_mat) { expr->set_result_type( - mod_->create(rhs_mat->type(), rhs_mat->columns())); + mod_->create(rhs_mat->type(), rhs_mat->columns())); } else if (lhs_mat) { // matrix * scalar expr->set_result_type(lhs_type); @@ -1205,61 +1203,60 @@ bool TypeDeterminer::DetermineUnaryOp(ast::UnaryOpExpression* expr) { return true; } -bool TypeDeterminer::DetermineStorageTextureSubtype( - ast::type::StorageTexture* tex) { +bool TypeDeterminer::DetermineStorageTextureSubtype(type::StorageTexture* tex) { if (tex->type() != nullptr) { return true; } switch (tex->image_format()) { - case ast::type::ImageFormat::kR8Uint: - case ast::type::ImageFormat::kR16Uint: - case ast::type::ImageFormat::kRg8Uint: - case ast::type::ImageFormat::kR32Uint: - case ast::type::ImageFormat::kRg16Uint: - case ast::type::ImageFormat::kRgba8Uint: - case ast::type::ImageFormat::kRg32Uint: - case ast::type::ImageFormat::kRgba16Uint: - case ast::type::ImageFormat::kRgba32Uint: { - tex->set_type(mod_->create()); + case type::ImageFormat::kR8Uint: + case type::ImageFormat::kR16Uint: + case type::ImageFormat::kRg8Uint: + case type::ImageFormat::kR32Uint: + case type::ImageFormat::kRg16Uint: + case type::ImageFormat::kRgba8Uint: + case type::ImageFormat::kRg32Uint: + case type::ImageFormat::kRgba16Uint: + case type::ImageFormat::kRgba32Uint: { + tex->set_type(mod_->create()); return true; } - case ast::type::ImageFormat::kR8Sint: - case ast::type::ImageFormat::kR16Sint: - case ast::type::ImageFormat::kRg8Sint: - case ast::type::ImageFormat::kR32Sint: - case ast::type::ImageFormat::kRg16Sint: - case ast::type::ImageFormat::kRgba8Sint: - case ast::type::ImageFormat::kRg32Sint: - case ast::type::ImageFormat::kRgba16Sint: - case ast::type::ImageFormat::kRgba32Sint: { - tex->set_type(mod_->create()); + case type::ImageFormat::kR8Sint: + case type::ImageFormat::kR16Sint: + case type::ImageFormat::kRg8Sint: + case type::ImageFormat::kR32Sint: + case type::ImageFormat::kRg16Sint: + case type::ImageFormat::kRgba8Sint: + case type::ImageFormat::kRg32Sint: + case type::ImageFormat::kRgba16Sint: + case type::ImageFormat::kRgba32Sint: { + tex->set_type(mod_->create()); return true; } - case ast::type::ImageFormat::kR8Unorm: - case ast::type::ImageFormat::kRg8Unorm: - case ast::type::ImageFormat::kRgba8Unorm: - case ast::type::ImageFormat::kRgba8UnormSrgb: - case ast::type::ImageFormat::kBgra8Unorm: - case ast::type::ImageFormat::kBgra8UnormSrgb: - case ast::type::ImageFormat::kRgb10A2Unorm: - case ast::type::ImageFormat::kR8Snorm: - case ast::type::ImageFormat::kRg8Snorm: - case ast::type::ImageFormat::kRgba8Snorm: - case ast::type::ImageFormat::kR16Float: - case ast::type::ImageFormat::kR32Float: - case ast::type::ImageFormat::kRg16Float: - case ast::type::ImageFormat::kRg11B10Float: - case ast::type::ImageFormat::kRg32Float: - case ast::type::ImageFormat::kRgba16Float: - case ast::type::ImageFormat::kRgba32Float: { - tex->set_type(mod_->create()); + case type::ImageFormat::kR8Unorm: + case type::ImageFormat::kRg8Unorm: + case type::ImageFormat::kRgba8Unorm: + case type::ImageFormat::kRgba8UnormSrgb: + case type::ImageFormat::kBgra8Unorm: + case type::ImageFormat::kBgra8UnormSrgb: + case type::ImageFormat::kRgb10A2Unorm: + case type::ImageFormat::kR8Snorm: + case type::ImageFormat::kRg8Snorm: + case type::ImageFormat::kRgba8Snorm: + case type::ImageFormat::kR16Float: + case type::ImageFormat::kR32Float: + case type::ImageFormat::kRg16Float: + case type::ImageFormat::kRg11B10Float: + case type::ImageFormat::kRg32Float: + case type::ImageFormat::kRgba16Float: + case type::ImageFormat::kRgba32Float: { + tex->set_type(mod_->create()); return true; } - case ast::type::ImageFormat::kNone: + case type::ImageFormat::kNone: break; } diff --git a/src/type_determiner.h b/src/type_determiner.h index 479bbca72b..f2aa2ba58d 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h @@ -20,8 +20,8 @@ #include #include "src/ast/module.h" -#include "src/ast/type/storage_texture_type.h" #include "src/scope_stack.h" +#include "src/type/storage_texture_type.h" namespace tint { namespace ast { @@ -84,7 +84,7 @@ class TypeDeterminer { /// Determines the result type based off a storage texture format /// @param tex the storage texture /// @returns false on error - bool DetermineStorageTextureSubtype(ast::type::StorageTexture* tex); + bool DetermineStorageTextureSubtype(type::StorageTexture* tex); /// Testing method to set a given variable into the type stack /// @param var the variable to set @@ -99,11 +99,11 @@ class TypeDeterminer { /// @param params the parameters to the method call /// @param id out parameter for the external call ID. Must not be a nullptr. /// @returns the return type of `name` in `path` or nullptr on error. - ast::type::Type* GetImportData(const Source& src, - const std::string& path, - const std::string& name, - const ast::ExpressionList& params, - uint32_t* id); + type::Type* GetImportData(const Source& src, + const std::string& path, + const std::string& name, + const ast::ExpressionList& params, + uint32_t* id); /// Sets the intrinsic data information for the identifier if needed /// @param ident the identifier expression diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 42c9c7add8..1436199866 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -47,26 +47,26 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" namespace tint { namespace { @@ -133,8 +133,8 @@ TEST_F(TypeDeterminerTest, Stmt_Assign) { ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); - EXPECT_TRUE(lhs->result_type()->Is()); - EXPECT_TRUE(rhs->result_type()->Is()); + EXPECT_TRUE(lhs->result_type()->Is()); + EXPECT_TRUE(rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Case) { @@ -151,8 +151,8 @@ TEST_F(TypeDeterminerTest, Stmt_Case) { EXPECT_TRUE(td()->DetermineResultType(cse)); ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); - EXPECT_TRUE(lhs->result_type()->Is()); - EXPECT_TRUE(rhs->result_type()->Is()); + EXPECT_TRUE(lhs->result_type()->Is()); + EXPECT_TRUE(rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Block) { @@ -166,8 +166,8 @@ TEST_F(TypeDeterminerTest, Stmt_Block) { EXPECT_TRUE(td()->DetermineResultType(block)); ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); - EXPECT_TRUE(lhs->result_type()->Is()); - EXPECT_TRUE(rhs->result_type()->Is()); + EXPECT_TRUE(lhs->result_type()->Is()); + EXPECT_TRUE(rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Else) { @@ -183,9 +183,9 @@ TEST_F(TypeDeterminerTest, Stmt_Else) { ASSERT_NE(stmt->condition()->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); - EXPECT_TRUE(stmt->condition()->result_type()->Is()); - EXPECT_TRUE(lhs->result_type()->Is()); - EXPECT_TRUE(rhs->result_type()->Is()); + EXPECT_TRUE(stmt->condition()->result_type()->Is()); + EXPECT_TRUE(lhs->result_type()->Is()); + EXPECT_TRUE(rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_If) { @@ -213,11 +213,11 @@ TEST_F(TypeDeterminerTest, Stmt_If) { ASSERT_NE(else_rhs->result_type(), nullptr); ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); - EXPECT_TRUE(stmt->condition()->result_type()->Is()); - EXPECT_TRUE(else_lhs->result_type()->Is()); - EXPECT_TRUE(else_rhs->result_type()->Is()); - EXPECT_TRUE(lhs->result_type()->Is()); - EXPECT_TRUE(rhs->result_type()->Is()); + EXPECT_TRUE(stmt->condition()->result_type()->Is()); + EXPECT_TRUE(else_lhs->result_type()->Is()); + EXPECT_TRUE(else_rhs->result_type()->Is()); + EXPECT_TRUE(lhs->result_type()->Is()); + EXPECT_TRUE(rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Loop) { @@ -242,10 +242,10 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) { ASSERT_NE(body_rhs->result_type(), nullptr); ASSERT_NE(continuing_lhs->result_type(), nullptr); ASSERT_NE(continuing_rhs->result_type(), nullptr); - EXPECT_TRUE(body_lhs->result_type()->Is()); - EXPECT_TRUE(body_rhs->result_type()->Is()); - EXPECT_TRUE(continuing_lhs->result_type()->Is()); - EXPECT_TRUE(continuing_rhs->result_type()->Is()); + EXPECT_TRUE(body_lhs->result_type()->Is()); + EXPECT_TRUE(body_rhs->result_type()->Is()); + EXPECT_TRUE(continuing_lhs->result_type()->Is()); + EXPECT_TRUE(continuing_rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Return) { @@ -255,7 +255,7 @@ TEST_F(TypeDeterminerTest, Stmt_Return) { EXPECT_TRUE(td()->DetermineResultType(ret)); ASSERT_NE(cond->result_type(), nullptr); - EXPECT_TRUE(cond->result_type()->Is()); + EXPECT_TRUE(cond->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Return_WithoutValue) { @@ -283,9 +283,9 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) { ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); - EXPECT_TRUE(stmt->condition()->result_type()->Is()); - EXPECT_TRUE(lhs->result_type()->Is()); - EXPECT_TRUE(rhs->result_type()->Is()); + EXPECT_TRUE(stmt->condition()->result_type()->Is()); + EXPECT_TRUE(lhs->result_type()->Is()); + EXPECT_TRUE(rhs->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Call) { @@ -302,7 +302,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call) { auto* call = create(expr); EXPECT_TRUE(td()->DetermineResultType(call)); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) { @@ -342,7 +342,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl) { EXPECT_TRUE(td()->DetermineResultType(decl)); ASSERT_NE(init->result_type(), nullptr); - EXPECT_TRUE(init->result_type()->Is()); + EXPECT_TRUE(init->result_type()->Is()); } TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) { @@ -354,7 +354,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) { EXPECT_TRUE(td()->Determine()); ASSERT_NE(init->result_type(), nullptr); - EXPECT_TRUE(init->result_type()->Is()); + EXPECT_TRUE(init->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Error_Unknown) { @@ -374,10 +374,10 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) { auto* acc = IndexAccessor("my_var", idx); EXPECT_TRUE(td()->DetermineResultType(acc)); ASSERT_NE(acc->result_type(), nullptr); - ASSERT_TRUE(acc->result_type()->Is()); + ASSERT_TRUE(acc->result_type()->Is()); - auto* ptr = acc->result_type()->As(); - EXPECT_TRUE(ptr->type()->Is()); + auto* ptr = acc->result_type()->As(); + EXPECT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) { @@ -390,10 +390,10 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) { auto* acc = IndexAccessor("my_var", 2); EXPECT_TRUE(td()->DetermineResultType(acc)); ASSERT_NE(acc->result_type(), nullptr); - ASSERT_TRUE(acc->result_type()->Is()); + ASSERT_TRUE(acc->result_type()->Is()); - auto* ptr = acc->result_type()->As(); - EXPECT_TRUE(ptr->type()->Is()); + auto* ptr = acc->result_type()->As(); + EXPECT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) { @@ -405,7 +405,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) { auto* acc = IndexAccessor("my_var", 2); EXPECT_TRUE(td()->DetermineResultType(acc)); ASSERT_NE(acc->result_type(), nullptr); - EXPECT_TRUE(acc->result_type()->Is()) + EXPECT_TRUE(acc->result_type()->Is()) << acc->result_type()->type_name(); } @@ -418,11 +418,11 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) { auto* acc = IndexAccessor("my_var", 2); EXPECT_TRUE(td()->DetermineResultType(acc)); ASSERT_NE(acc->result_type(), nullptr); - ASSERT_TRUE(acc->result_type()->Is()); + ASSERT_TRUE(acc->result_type()->Is()); - auto* ptr = acc->result_type()->As(); - ASSERT_TRUE(ptr->type()->Is()); - EXPECT_EQ(ptr->type()->As()->size(), 3u); + auto* ptr = acc->result_type()->As(); + ASSERT_TRUE(ptr->type()->Is()); + EXPECT_EQ(ptr->type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) { @@ -435,10 +435,10 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) { EXPECT_TRUE(td()->DetermineResultType(acc)); ASSERT_NE(acc->result_type(), nullptr); - ASSERT_TRUE(acc->result_type()->Is()); + ASSERT_TRUE(acc->result_type()->Is()); - auto* ptr = acc->result_type()->As(); - EXPECT_TRUE(ptr->type()->Is()); + auto* ptr = acc->result_type()->As(); + EXPECT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) { @@ -450,10 +450,10 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) { auto* acc = IndexAccessor("my_var", 2); EXPECT_TRUE(td()->DetermineResultType(acc)); ASSERT_NE(acc->result_type(), nullptr); - ASSERT_TRUE(acc->result_type()->Is()); + ASSERT_TRUE(acc->result_type()->Is()); - auto* ptr = acc->result_type()->As(); - EXPECT_TRUE(ptr->type()->Is()); + auto* ptr = acc->result_type()->As(); + EXPECT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Bitcast) { @@ -464,7 +464,7 @@ TEST_F(TypeDeterminerTest, Expr_Bitcast) { EXPECT_TRUE(td()->DetermineResultType(bitcast)); ASSERT_NE(bitcast->result_type(), nullptr); - EXPECT_TRUE(bitcast->result_type()->Is()); + EXPECT_TRUE(bitcast->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Call) { @@ -479,7 +479,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) { auto* call = Call("my_func"); EXPECT_TRUE(td()->DetermineResultType(call)); ASSERT_NE(call->result_type(), nullptr); - EXPECT_TRUE(call->result_type()->Is()); + EXPECT_TRUE(call->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Call_WithParams) { @@ -496,7 +496,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) { auto* call = Call("my_func", param); EXPECT_TRUE(td()->DetermineResultType(call)); ASSERT_NE(param->result_type(), nullptr); - EXPECT_TRUE(param->result_type()->Is()); + EXPECT_TRUE(param->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Call_Intrinsic) { @@ -507,7 +507,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_Intrinsic) { EXPECT_TRUE(td()->DetermineResultType(call)); ASSERT_NE(call->result_type(), nullptr); - EXPECT_TRUE(call->result_type()->Is()); + EXPECT_TRUE(call->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Cast) { @@ -518,14 +518,14 @@ TEST_F(TypeDeterminerTest, Expr_Cast) { EXPECT_TRUE(td()->DetermineResultType(cast)); ASSERT_NE(cast->result_type(), nullptr); - EXPECT_TRUE(cast->result_type()->Is()); + EXPECT_TRUE(cast->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) { auto* s = Expr(1.0f); EXPECT_TRUE(td()->DetermineResultType(s)); ASSERT_NE(s->result_type(), nullptr); - EXPECT_TRUE(s->result_type()->Is()); + EXPECT_TRUE(s->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Constructor_Type) { @@ -533,10 +533,9 @@ TEST_F(TypeDeterminerTest, Expr_Constructor_Type) { EXPECT_TRUE(td()->DetermineResultType(tc)); ASSERT_NE(tc->result_type(), nullptr); - ASSERT_TRUE(tc->result_type()->Is()); - EXPECT_TRUE( - tc->result_type()->As()->type()->Is()); - EXPECT_EQ(tc->result_type()->As()->size(), 3u); + ASSERT_TRUE(tc->result_type()->Is()); + EXPECT_TRUE(tc->result_type()->As()->type()->Is()); + EXPECT_EQ(tc->result_type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) { @@ -548,11 +547,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) { auto* ident = Expr("my_var"); EXPECT_TRUE(td()->DetermineResultType(ident)); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); - EXPECT_TRUE(ident->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE( + ident->result_type()->As()->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalConstant) { @@ -563,7 +560,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalConstant) { auto* ident = Expr("my_var"); EXPECT_TRUE(td()->DetermineResultType(ident)); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) { @@ -581,7 +578,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) { EXPECT_TRUE(td()->DetermineFunction(f)); ASSERT_NE(my_var->result_type(), nullptr); - EXPECT_TRUE(my_var->result_type()->Is()); + EXPECT_TRUE(my_var->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) { @@ -598,15 +595,13 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) { EXPECT_TRUE(td()->DetermineFunction(f)); ASSERT_NE(my_var->result_type(), nullptr); - EXPECT_TRUE(my_var->result_type()->Is()); - EXPECT_TRUE(my_var->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE(my_var->result_type()->Is()); + EXPECT_TRUE( + my_var->result_type()->As()->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) { - ast::type::Pointer ptr(ty.f32, ast::StorageClass::kFunction); + type::Pointer ptr(ty.f32, ast::StorageClass::kFunction); auto* my_var = Expr("my_var"); @@ -621,11 +616,9 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) { EXPECT_TRUE(td()->DetermineFunction(f)); ASSERT_NE(my_var->result_type(), nullptr); - EXPECT_TRUE(my_var->result_type()->Is()); - EXPECT_TRUE(my_var->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE(my_var->result_type()->Is()); + EXPECT_TRUE( + my_var->result_type()->As()->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { @@ -639,7 +632,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { auto* ident = Expr("my_func"); EXPECT_TRUE(td()->DetermineResultType(ident)); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Identifier_Unknown) { @@ -768,10 +761,10 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) { auto* mem = MemberAccessor("my_struct", "second_member"); EXPECT_TRUE(td()->DetermineResultType(mem)); ASSERT_NE(mem->result_type(), nullptr); - ASSERT_TRUE(mem->result_type()->Is()); + ASSERT_TRUE(mem->result_type()->Is()); - auto* ptr = mem->result_type()->As(); - EXPECT_TRUE(ptr->type()->Is()); + auto* ptr = mem->result_type()->As(); + EXPECT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) { @@ -791,10 +784,10 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) { auto* mem = MemberAccessor("my_struct", "second_member"); EXPECT_TRUE(td()->DetermineResultType(mem)); ASSERT_NE(mem->result_type(), nullptr); - ASSERT_TRUE(mem->result_type()->Is()); + ASSERT_TRUE(mem->result_type()->Is()); - auto* ptr = mem->result_type()->As(); - EXPECT_TRUE(ptr->type()->Is()); + auto* ptr = mem->result_type()->As(); + EXPECT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) { @@ -806,12 +799,9 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) { auto* mem = MemberAccessor("my_vec", "xy"); EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error(); ASSERT_NE(mem->result_type(), nullptr); - ASSERT_TRUE(mem->result_type()->Is()); - EXPECT_TRUE(mem->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(mem->result_type()->As()->size(), 2u); + ASSERT_TRUE(mem->result_type()->Is()); + EXPECT_TRUE(mem->result_type()->As()->type()->Is()); + EXPECT_EQ(mem->result_type()->As()->size(), 2u); } TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) { @@ -823,10 +813,10 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) { auto* mem = MemberAccessor("my_vec", "x"); EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error(); ASSERT_NE(mem->result_type(), nullptr); - ASSERT_TRUE(mem->result_type()->Is()); + ASSERT_TRUE(mem->result_type()->Is()); - auto* ptr = mem->result_type()->As(); - ASSERT_TRUE(ptr->type()->Is()); + auto* ptr = mem->result_type()->As(); + ASSERT_TRUE(ptr->type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) { @@ -860,7 +850,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) { ast::StructDecorationList{}); auto* stB = ty.struct_("B", strctB); - ast::type::Vector vecB(stB, 3); + type::Vector vecB(stB, 3); auto* strctA = create( ast::StructMemberList{Member("mem", &vecB)}, ast::StructDecorationList{}); @@ -875,12 +865,9 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) { EXPECT_TRUE(td()->DetermineResultType(mem)) << td()->error(); ASSERT_NE(mem->result_type(), nullptr); - ASSERT_TRUE(mem->result_type()->Is()); - EXPECT_TRUE(mem->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(mem->result_type()->As()->size(), 2u); + ASSERT_TRUE(mem->result_type()->Is()); + EXPECT_TRUE(mem->result_type()->As()->type()->Is()); + EXPECT_EQ(mem->result_type()->As()->size(), 2u); } using Expr_Binary_BitwiseTest = TypeDeterminerTestWithParam; @@ -897,7 +884,7 @@ TEST_P(Expr_Binary_BitwiseTest, Scalar) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_P(Expr_Binary_BitwiseTest, Vector) { @@ -913,12 +900,9 @@ TEST_P(Expr_Binary_BitwiseTest, Vector) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, Expr_Binary_BitwiseTest, @@ -946,7 +930,7 @@ TEST_P(Expr_Binary_LogicalTest, Scalar) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_P(Expr_Binary_LogicalTest, Vector) { @@ -962,12 +946,10 @@ TEST_P(Expr_Binary_LogicalTest, Vector) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, Expr_Binary_LogicalTest, @@ -988,7 +970,7 @@ TEST_P(Expr_Binary_CompareTest, Scalar) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_P(Expr_Binary_CompareTest, Vector) { @@ -1004,12 +986,10 @@ TEST_P(Expr_Binary_CompareTest, Vector) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, Expr_Binary_CompareTest, @@ -1031,7 +1011,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) { @@ -1046,12 +1026,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) { @@ -1066,12 +1043,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) { @@ -1084,12 +1058,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) { @@ -1104,10 +1075,10 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); + ASSERT_TRUE(expr->result_type()->Is()); - auto* mat = expr->result_type()->As(); - EXPECT_TRUE(mat->type()->Is()); + auto* mat = expr->result_type()->As(); + EXPECT_TRUE(mat->type()->Is()); EXPECT_EQ(mat->rows(), 3u); EXPECT_EQ(mat->columns(), 2u); } @@ -1124,10 +1095,10 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); + ASSERT_TRUE(expr->result_type()->Is()); - auto* mat = expr->result_type()->As(); - EXPECT_TRUE(mat->type()->Is()); + auto* mat = expr->result_type()->As(); + EXPECT_TRUE(mat->type()->Is()); EXPECT_EQ(mat->rows(), 3u); EXPECT_EQ(mat->columns(), 2u); } @@ -1144,12 +1115,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Vector) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) { @@ -1164,12 +1132,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 2u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 2u); } TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) { @@ -1184,10 +1149,10 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) { ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); + ASSERT_TRUE(expr->result_type()->Is()); - auto* mat = expr->result_type()->As(); - EXPECT_TRUE(mat->type()->Is()); + auto* mat = expr->result_type()->As(); + EXPECT_TRUE(mat->type()->Is()); EXPECT_EQ(mat->rows(), 4u); EXPECT_EQ(mat->columns(), 4u); } @@ -1206,7 +1171,7 @@ TEST_P(IntrinsicDerivativeTest, Scalar) { EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); + ASSERT_TRUE(expr->result_type()->Is()); } TEST_P(IntrinsicDerivativeTest, Vector) { @@ -1222,12 +1187,9 @@ TEST_P(IntrinsicDerivativeTest, Vector) { EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 4u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 4u); } TEST_P(IntrinsicDerivativeTest, MissingParam) { @@ -1281,7 +1243,7 @@ TEST_P(Intrinsic, Test) { EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, Intrinsic, @@ -1302,12 +1264,10 @@ TEST_P(Intrinsic_FloatMethod, Vector) { EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); + ASSERT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); } TEST_P(Intrinsic_FloatMethod, Scalar) { @@ -1323,7 +1283,7 @@ TEST_P(Intrinsic_FloatMethod, Scalar) { EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_P(Intrinsic_FloatMethod, MissingParam) { @@ -1373,9 +1333,9 @@ inline std::ostream& operator<<(std::ostream& out, Texture data) { } struct TextureTestParams { - ast::type::TextureDimension dim; + type::TextureDimension dim; Texture type = Texture::kF32; - ast::type::ImageFormat format = ast::type::ImageFormat::kR16Float; + type::ImageFormat format = type::ImageFormat::kR16Float; }; inline std::ostream& operator<<(std::ostream& out, TextureTestParams data) { out << data.dim << "_" << data.type; @@ -1385,43 +1345,42 @@ inline std::ostream& operator<<(std::ostream& out, TextureTestParams data) { class Intrinsic_TextureOperation : public TypeDeterminerTestWithParam { public: - std::unique_ptr get_coords_type( - ast::type::TextureDimension dim, - ast::type::Type* type) { - if (dim == ast::type::TextureDimension::k1d) { - if (type->Is()) { - return std::make_unique(); - } else if (type->Is()) { - return std::make_unique(); + std::unique_ptr get_coords_type(type::TextureDimension dim, + type::Type* type) { + if (dim == type::TextureDimension::k1d) { + if (type->Is()) { + return std::make_unique(); + } else if (type->Is()) { + return std::make_unique(); } else { - return std::make_unique(); + return std::make_unique(); } - } else if (dim == ast::type::TextureDimension::k1dArray || - dim == ast::type::TextureDimension::k2d) { - return std::make_unique(type, 2); - } else if (dim == ast::type::TextureDimension::kCubeArray) { - return std::make_unique(type, 4); + } else if (dim == type::TextureDimension::k1dArray || + dim == type::TextureDimension::k2d) { + return std::make_unique(type, 2); + } else if (dim == type::TextureDimension::kCubeArray) { + return std::make_unique(type, 4); } else { - return std::make_unique(type, 3); + return std::make_unique(type, 3); } } void add_call_param(std::string name, - ast::type::Type* type, + type::Type* type, ast::ExpressionList* call_params) { auto* var = Var(name, ast::StorageClass::kNone, type); mod->AddGlobalVariable(var); call_params->push_back(Expr(name)); } - std::unique_ptr subtype(Texture type) { + std::unique_ptr subtype(Texture type) { if (type == Texture::kF32) { - return std::make_unique(); + return std::make_unique(); } if (type == Texture::kI32) { - return std::make_unique(); + return std::make_unique(); } - return std::make_unique(); + return std::make_unique(); } }; @@ -1433,8 +1392,7 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) { auto coords_type = get_coords_type(dim, ty.i32); - ast::type::Type* texture_type = - mod->create(dim, format); + type::Type* texture_type = mod->create(dim, format); ast::ExpressionList call_params; @@ -1448,69 +1406,63 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) { EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); + ASSERT_TRUE(expr->result_type()->Is()); if (type == Texture::kF32) { - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); } else if (type == Texture::kI32) { - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); } else { - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); } - EXPECT_EQ(expr->result_type()->As()->size(), 4u); + EXPECT_EQ(expr->result_type()->As()->size(), 4u); } INSTANTIATE_TEST_SUITE_P( TypeDeterminerTest, Intrinsic_StorageTextureOperation, testing::Values( - TextureTestParams{ast::type::TextureDimension::k1d, Texture::kF32, - ast::type::ImageFormat::kR16Float}, - TextureTestParams{ast::type::TextureDimension::k1d, Texture::kI32, - ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k1d, Texture::kF32, - ast::type::ImageFormat::kR8Unorm}, - TextureTestParams{ast::type::TextureDimension::k1dArray, Texture::kF32, - ast::type::ImageFormat::kR16Float}, - TextureTestParams{ast::type::TextureDimension::k1dArray, Texture::kI32, - ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k1dArray, Texture::kF32, - ast::type::ImageFormat::kR8Unorm}, - TextureTestParams{ast::type::TextureDimension::k2d, Texture::kF32, - ast::type::ImageFormat::kR16Float}, - TextureTestParams{ast::type::TextureDimension::k2d, Texture::kI32, - ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k2d, Texture::kF32, - ast::type::ImageFormat::kR8Unorm}, - TextureTestParams{ast::type::TextureDimension::k2dArray, Texture::kF32, - ast::type::ImageFormat::kR16Float}, - TextureTestParams{ast::type::TextureDimension::k2dArray, Texture::kI32, - ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k2dArray, Texture::kF32, - ast::type::ImageFormat::kR8Unorm}, - TextureTestParams{ast::type::TextureDimension::k3d, Texture::kF32, - ast::type::ImageFormat::kR16Float}, - TextureTestParams{ast::type::TextureDimension::k3d, Texture::kI32, - ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k3d, Texture::kF32, - ast::type::ImageFormat::kR8Unorm})); + TextureTestParams{type::TextureDimension::k1d, Texture::kF32, + type::ImageFormat::kR16Float}, + TextureTestParams{type::TextureDimension::k1d, Texture::kI32, + type::ImageFormat::kR16Sint}, + TextureTestParams{type::TextureDimension::k1d, Texture::kF32, + type::ImageFormat::kR8Unorm}, + TextureTestParams{type::TextureDimension::k1dArray, Texture::kF32, + type::ImageFormat::kR16Float}, + TextureTestParams{type::TextureDimension::k1dArray, Texture::kI32, + type::ImageFormat::kR16Sint}, + TextureTestParams{type::TextureDimension::k1dArray, Texture::kF32, + type::ImageFormat::kR8Unorm}, + TextureTestParams{type::TextureDimension::k2d, Texture::kF32, + type::ImageFormat::kR16Float}, + TextureTestParams{type::TextureDimension::k2d, Texture::kI32, + type::ImageFormat::kR16Sint}, + TextureTestParams{type::TextureDimension::k2d, Texture::kF32, + type::ImageFormat::kR8Unorm}, + TextureTestParams{type::TextureDimension::k2dArray, Texture::kF32, + type::ImageFormat::kR16Float}, + TextureTestParams{type::TextureDimension::k2dArray, Texture::kI32, + type::ImageFormat::kR16Sint}, + TextureTestParams{type::TextureDimension::k2dArray, Texture::kF32, + type::ImageFormat::kR8Unorm}, + TextureTestParams{type::TextureDimension::k3d, Texture::kF32, + type::ImageFormat::kR16Float}, + TextureTestParams{type::TextureDimension::k3d, Texture::kI32, + type::ImageFormat::kR16Sint}, + TextureTestParams{type::TextureDimension::k3d, Texture::kF32, + type::ImageFormat::kR8Unorm})); using Intrinsic_SampledTextureOperation = Intrinsic_TextureOperation; TEST_P(Intrinsic_SampledTextureOperation, TextureLoadSampled) { auto dim = GetParam().dim; auto type = GetParam().type; - std::unique_ptr s = subtype(type); + std::unique_ptr s = subtype(type); auto coords_type = get_coords_type(dim, ty.i32); - auto texture_type = std::make_unique(dim, s.get()); + auto texture_type = std::make_unique(dim, s.get()); ast::ExpressionList call_params; @@ -1524,34 +1476,27 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureLoadSampled) { EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - ASSERT_TRUE(expr->result_type()->Is()); + ASSERT_TRUE(expr->result_type()->Is()); if (type == Texture::kF32) { - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); } else if (type == Texture::kI32) { - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); } else { - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE( + expr->result_type()->As()->type()->Is()); } - EXPECT_EQ(expr->result_type()->As()->size(), 4u); + EXPECT_EQ(expr->result_type()->As()->size(), 4u); } INSTANTIATE_TEST_SUITE_P( TypeDeterminerTest, Intrinsic_SampledTextureOperation, - testing::Values(TextureTestParams{ast::type::TextureDimension::k2d}, - TextureTestParams{ast::type::TextureDimension::k2dArray}, - TextureTestParams{ast::type::TextureDimension::kCube}, - TextureTestParams{ - ast::type::TextureDimension::kCubeArray})); + testing::Values(TextureTestParams{type::TextureDimension::k2d}, + TextureTestParams{type::TextureDimension::k2dArray}, + TextureTestParams{type::TextureDimension::kCube}, + TextureTestParams{type::TextureDimension::kCubeArray})); TEST_F(TypeDeterminerTest, Intrinsic_Dot) { auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3()); @@ -1564,7 +1509,7 @@ TEST_F(TypeDeterminerTest, Intrinsic_Dot) { EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->DetermineResultType(expr)); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_TRUE(expr->result_type()->Is()); } TEST_F(TypeDeterminerTest, Intrinsic_Select) { @@ -1581,12 +1526,9 @@ TEST_F(TypeDeterminerTest, Intrinsic_Select) { EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->DetermineResultType(expr)) << td()->error(); ASSERT_NE(expr->result_type(), nullptr); - EXPECT_TRUE(expr->result_type()->Is()); - EXPECT_EQ(expr->result_type()->As()->size(), 3u); - EXPECT_TRUE(expr->result_type() - ->As() - ->type() - ->Is()); + EXPECT_TRUE(expr->result_type()->Is()); + EXPECT_EQ(expr->result_type()->As()->size(), 3u); + EXPECT_TRUE(expr->result_type()->As()->type()->Is()); } TEST_F(TypeDeterminerTest, Intrinsic_Select_TooFewParams) { @@ -1630,12 +1572,9 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) { auto* der = create(op, Expr("ident")); EXPECT_TRUE(td()->DetermineResultType(der)); ASSERT_NE(der->result_type(), nullptr); - ASSERT_TRUE(der->result_type()->Is()); - EXPECT_TRUE(der->result_type() - ->As() - ->type() - ->Is()); - EXPECT_EQ(der->result_type()->As()->size(), 4u); + ASSERT_TRUE(der->result_type()->Is()); + EXPECT_TRUE(der->result_type()->As()->type()->Is()); + EXPECT_EQ(der->result_type()->As()->size(), 4u); } INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, UnaryOpExpressionTest, @@ -1804,7 +1743,7 @@ TEST_P(ImportData_SingleParamTest, Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_SingleParamTest, Error_Integer) { @@ -1886,7 +1825,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Float_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_SingleParam_FloatOrInt_Test, Sint_Scalar) { @@ -1897,7 +1836,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Sint_Scalar) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_SingleParam_FloatOrInt_Test, Sint_Vector) { @@ -1917,7 +1856,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Sint_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_signed_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_SingleParam_FloatOrInt_Test, Uint_Scalar) { @@ -1931,7 +1870,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Uint_Scalar) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_SingleParam_FloatOrInt_Test, Uint_Vector) { @@ -1943,7 +1882,7 @@ TEST_P(ImportData_SingleParam_FloatOrInt_Test, Uint_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_unsigned_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_SingleParam_FloatOrInt_Test, Error_Bool) { @@ -2057,7 +1996,7 @@ TEST_P(ImportData_TwoParamTest, Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_TwoParamTest, Error_Integer) { @@ -2148,7 +2087,7 @@ TEST_F(TypeDeterminerTest, ImportData_Distance_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_F(TypeDeterminerTest, ImportData_Distance_Error_Integer) { @@ -2208,7 +2147,7 @@ TEST_F(TypeDeterminerTest, ImportData_Cross) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_F(TypeDeterminerTest, ImportData_Cross_Error_Scalar) { @@ -2274,7 +2213,7 @@ TEST_P(ImportData_ThreeParamTest, Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_ThreeParamTest, Error_Integer) { @@ -2381,7 +2320,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Float_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Sint_Scalar) { @@ -2392,7 +2331,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Sint_Scalar) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Sint_Vector) { @@ -2405,7 +2344,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Sint_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_signed_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Uint_Scalar) { @@ -2416,7 +2355,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Uint_Scalar) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Uint_Vector) { @@ -2429,7 +2368,7 @@ TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Uint_Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_unsigned_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_ThreeParam_FloatOrInt_Test, Error_Bool) { @@ -2531,7 +2470,7 @@ TEST_P(ImportData_Int_SingleParamTest, Vector) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_signed_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_Int_SingleParamTest, Error_Float) { @@ -2582,7 +2521,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Signed) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Unsigned) { @@ -2593,7 +2532,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Unsigned) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Float) { @@ -2604,7 +2543,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Scalar_Float) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Vector_Signed) { @@ -2616,7 +2555,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Vector_Signed) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_signed_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Vector_Unsigned) { @@ -2628,7 +2567,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Vector_Unsigned) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_unsigned_integer_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Vector_Float) { @@ -2640,7 +2579,7 @@ TEST_P(ImportData_FloatOrInt_TwoParamTest, Vector_Float) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); EXPECT_TRUE(ident->result_type()->is_float_vector()); - EXPECT_EQ(ident->result_type()->As()->size(), 3u); + EXPECT_EQ(ident->result_type()->As()->size(), 3u); } TEST_P(ImportData_FloatOrInt_TwoParamTest, Error_Bool) { @@ -2722,7 +2661,7 @@ TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant) { EXPECT_TRUE(td()->DetermineResultType(call)) << td()->error(); ASSERT_NE(ident->result_type(), nullptr); - EXPECT_TRUE(ident->result_type()->Is()); + EXPECT_TRUE(ident->result_type()->Is()); } using ImportData_Matrix_OneParam_Test = @@ -3190,18 +3129,18 @@ TEST_P(TypeDeterminerTextureIntrinsicTest, Call) { switch (param.texture_dimension) { default: FAIL() << "invalid texture dimensions: " << param.texture_dimension; - case ast::type::TextureDimension::k1d: - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1d: + case type::TextureDimension::k1dArray: EXPECT_EQ(call->result_type()->type_name(), ty.i32->type_name()); break; - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: EXPECT_EQ(call->result_type()->type_name(), ty.vec2()->type_name()); break; - case ast::type::TextureDimension::k3d: - case ast::type::TextureDimension::kCube: - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: EXPECT_EQ(call->result_type()->type_name(), ty.vec3()->type_name()); break; @@ -3220,9 +3159,8 @@ TEST_P(TypeDeterminerTextureIntrinsicTest, Call) { case ast::intrinsic::test::TextureKind::kMultisampled: case ast::intrinsic::test::TextureKind::kStorage: { auto* datatype = param.resultVectorComponentType(this); - ASSERT_TRUE(call->result_type()->Is()); - EXPECT_EQ(call->result_type()->As()->type(), - datatype); + ASSERT_TRUE(call->result_type()->Is()); + EXPECT_EQ(call->result_type()->As()->type(), datatype); break; } case ast::intrinsic::test::TextureKind::kDepth: { diff --git a/src/validator/validator_control_block_test.cc b/src/validator/validator_control_block_test.cc index 35b97a27c9..005abe3f3a 100644 --- a/src/validator/validator_control_block_test.cc +++ b/src/validator/validator_control_block_test.cc @@ -20,13 +20,13 @@ #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/alias_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" #include "src/type_determiner.h" #include "src/validator/validator_impl.h" #include "src/validator/validator_test_helper.h" diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc index 905d7b31a9..c5379bab40 100644 --- a/src/validator/validator_function_test.cc +++ b/src/validator/validator_function_test.cc @@ -20,11 +20,11 @@ #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/stage_decoration.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/validator/validator_impl.h" #include "src/validator/validator_test_helper.h" diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc index 15dfbbdf15..c673040d3d 100644 --- a/src/validator/validator_impl.cc +++ b/src/validator/validator_impl.cc @@ -27,16 +27,16 @@ #include "src/ast/stage_decoration.h" #include "src/ast/struct.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/uint_literal.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/array_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" namespace tint { @@ -83,11 +83,11 @@ bool ValidatorImpl::Validate() { } bool ValidatorImpl::ValidateConstructedTypes( - const std::vector& constructed_types) { + const std::vector& constructed_types) { for (auto* const ct : constructed_types) { - if (auto* st = ct->As()) { + if (auto* st = ct->As()) { for (auto* member : st->impl()->members()) { - if (auto* r = member->type()->UnwrapAll()->As()) { + if (auto* r = member->type()->UnwrapAll()->As()) { if (r->IsRuntimeArray()) { if (member != st->impl()->members().back()) { add_error(member->source(), "v-0015", @@ -167,7 +167,7 @@ bool ValidatorImpl::ValidateEntryPoint(const ast::FunctionList& funcs) { return false; } - if (!func->return_type()->Is()) { + if (!func->return_type()->Is()) { add_error(func->source(), "v-0024", "Entry point function must return void: '" + module_.SymbolToName(func->symbol()) + "'"); @@ -209,7 +209,7 @@ bool ValidatorImpl::ValidateFunction(const ast::Function* func) { } variable_stack_.pop_scope(); - if (!current_function_->return_type()->Is()) { + if (!current_function_->return_type()->Is()) { if (!func->get_last_statement() || !func->get_last_statement()->Is()) { add_error(func->source(), "v-0002", @@ -221,7 +221,7 @@ bool ValidatorImpl::ValidateFunction(const ast::Function* func) { } bool ValidatorImpl::ValidateParameter(const ast::Variable* param) { - if (auto* r = param->type()->UnwrapAll()->As()) { + if (auto* r = param->type()->UnwrapAll()->As()) { if (r->IsRuntimeArray()) { add_error( param->source(), "v-0015", @@ -235,9 +235,9 @@ bool ValidatorImpl::ValidateParameter(const ast::Variable* param) { bool ValidatorImpl::ValidateReturnStatement(const ast::ReturnStatement* ret) { // TODO(sarahM0): update this when this issue resolves: // https://github.com/gpuweb/gpuweb/issues/996 - ast::type::Type* func_type = current_function_->return_type(); + type::Type* func_type = current_function_->return_type(); - ast::type::Void void_type; + type::Void void_type; auto* ret_type = ret->has_value() ? ret->value()->result_type()->UnwrapAll() : &void_type; @@ -283,8 +283,7 @@ bool ValidatorImpl::ValidateDeclStatement( // storable. // - types match or the RHS can be dereferenced to equal the LHS type. variable_stack_.set(symbol, decl->variable()); - if (auto* arr = - decl->variable()->type()->UnwrapAll()->As()) { + if (auto* arr = decl->variable()->type()->UnwrapAll()->As()) { if (arr->IsRuntimeArray()) { add_error( decl->source(), "v-0015", @@ -358,11 +357,11 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) { } auto v = - static_cast(selector->type()->Is() + static_cast(selector->type()->Is() ? selector->As()->value() : selector->As()->value()); if (selector_set.count(v)) { - auto v_str = selector->type()->Is() + auto v_str = selector->type()->Is() ? selector->As()->to_str() : selector->As()->to_str(); add_error(case_stmt->source(), "v-0027", @@ -485,7 +484,7 @@ bool ValidatorImpl::ValidateAssign(const ast::AssignmentStatement* assign) { return false; } auto* lhs_result_type = lhs->result_type()->UnwrapIfNeeded(); - if (auto* lhs_reference_type = As(lhs_result_type)) { + if (auto* lhs_reference_type = As(lhs_result_type)) { auto* lhs_store_type = lhs_reference_type->type()->UnwrapIfNeeded(); if (lhs_store_type != rhs_result_type) { add_error(assign->source(), "v-000x", @@ -534,18 +533,18 @@ bool ValidatorImpl::ValidateIdentifier(const ast::IdentifierExpression* ident) { return true; } -bool ValidatorImpl::IsStorable(ast::type::Type* type) { +bool ValidatorImpl::IsStorable(type::Type* type) { if (type == nullptr) { return false; } - if (type->is_scalar() || type->Is() || - type->Is()) { + if (type->is_scalar() || type->Is() || + type->Is()) { return true; } - if (ast::type::Array* array_type = type->As()) { + if (type::Array* array_type = type->As()) { return IsStorable(array_type->type()); } - if (ast::type::Struct* struct_type = type->As()) { + if (type::Struct* struct_type = type->As()) { for (const auto* member : struct_type->impl()->members()) { if (!IsStorable(member->type())) { return false; @@ -553,7 +552,7 @@ bool ValidatorImpl::IsStorable(ast::type::Type* type) { } return true; } - if (ast::type::Alias* alias_type = type->As()) { + if (type::Alias* alias_type = type->As()) { return IsStorable(alias_type->type()); } return false; diff --git a/src/validator/validator_impl.h b/src/validator/validator_impl.h index f0a1b5d65f..58aa2e106c 100644 --- a/src/validator/validator_impl.h +++ b/src/validator/validator_impl.h @@ -144,15 +144,16 @@ class ValidatorImpl { /// @param constructed_types the types to check /// @returns true if the valdiation was successful bool ValidateConstructedTypes( - const std::vector& constructed_types); + const std::vector& constructed_types); /// Returns true if the given type is storable. This uses and /// updates `storable_` and `not_storable_`. /// @param type the given type /// @returns true if the given type is storable. - bool IsStorable(ast::type::Type* type); + bool IsStorable(type::Type* type); /// Testing method to inserting a given variable into the current scope. + /// @param var the variable to register void RegisterVariableForTesting(ast::Variable* var) { variable_stack_.set(var->symbol(), var); } diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc index de38988d14..7973dc7839 100644 --- a/src/validator/validator_test.cc +++ b/src/validator/validator_test.cc @@ -38,19 +38,19 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/validator/validator_impl.h" #include "src/validator/validator_test_helper.h" diff --git a/src/validator/validator_test_helper.h b/src/validator/validator_test_helper.h index a7f4374609..305f1a4f8a 100644 --- a/src/validator/validator_test_helper.h +++ b/src/validator/validator_test_helper.h @@ -19,7 +19,7 @@ #include #include "src/ast/builder.h" -#include "src/ast/type/void_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/validator/validator_impl.h" diff --git a/src/validator/validator_type_test.cc b/src/validator/validator_type_test.cc index 91be11991f..e1997857d1 100644 --- a/src/validator/validator_type_test.cc +++ b/src/validator/validator_type_test.cc @@ -18,13 +18,13 @@ #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" #include "src/validator/validator_impl.h" #include "src/validator/validator_test_helper.h" diff --git a/src/writer/append_vector.cc b/src/writer/append_vector.cc index 6a629b26ce..4873723760 100644 --- a/src/writer/append_vector.cc +++ b/src/writer/append_vector.cc @@ -17,8 +17,8 @@ #include #include "src/ast/expression.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/vector_type.h" namespace tint { namespace writer { @@ -27,7 +27,7 @@ namespace { ast::TypeConstructorExpression* AsVectorConstructor(ast::Expression* expr) { if (auto* constructor = expr->As()) { - if (constructor->type()->Is()) { + if (constructor->type()->Is()) { return constructor; } } @@ -41,8 +41,8 @@ bool AppendVector( ast::Expression* scalar, std::function callback) { uint32_t packed_size; - ast::type::Type* packed_el_ty; // Currently must be f32. - if (auto* vec = vector->result_type()->As()) { + type::Type* packed_el_ty; // Currently must be f32. + if (auto* vec = vector->result_type()->As()) { packed_size = vec->size() + 1; packed_el_ty = vec->type(); } else { @@ -58,7 +58,7 @@ bool AppendVector( ast::TypeConstructorExpression scalar_cast(Source{}, packed_el_ty, {scalar}); scalar_cast.set_result_type(packed_el_ty); - ast::type::Vector packed_ty(packed_el_ty, packed_size); + type::Vector packed_ty(packed_el_ty, packed_size); // If the coordinates are already passed in a vector constructor, extract // the elements into the new vector instead of nesting a vector-in-vector. diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index e3e53adb0b..c30a220e2c 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -39,25 +39,25 @@ #include "src/ast/sint_literal.h" #include "src/ast/struct.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/access_control_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/append_vector.h" #include "src/writer/float_to_string.h" @@ -97,27 +97,26 @@ uint32_t convert_swizzle_to_index(const std::string& swizzle) { return 0; } -const char* image_format_to_rwtexture_type( - ast::type::ImageFormat image_format) { +const char* image_format_to_rwtexture_type(type::ImageFormat image_format) { switch (image_format) { - case ast::type::ImageFormat::kRgba8Unorm: - case ast::type::ImageFormat::kRgba8Snorm: - case ast::type::ImageFormat::kRgba16Float: - case ast::type::ImageFormat::kR32Float: - case ast::type::ImageFormat::kRg32Float: - case ast::type::ImageFormat::kRgba32Float: + case type::ImageFormat::kRgba8Unorm: + case type::ImageFormat::kRgba8Snorm: + case type::ImageFormat::kRgba16Float: + case type::ImageFormat::kR32Float: + case type::ImageFormat::kRg32Float: + case type::ImageFormat::kRgba32Float: return "float4"; - case ast::type::ImageFormat::kRgba8Uint: - case ast::type::ImageFormat::kRgba16Uint: - case ast::type::ImageFormat::kR32Uint: - case ast::type::ImageFormat::kRg32Uint: - case ast::type::ImageFormat::kRgba32Uint: + case type::ImageFormat::kRgba8Uint: + case type::ImageFormat::kRgba16Uint: + case type::ImageFormat::kR32Uint: + case type::ImageFormat::kRg32Uint: + case type::ImageFormat::kRgba32Uint: return "uint4"; - case ast::type::ImageFormat::kRgba8Sint: - case ast::type::ImageFormat::kRgba16Sint: - case ast::type::ImageFormat::kR32Sint: - case ast::type::ImageFormat::kRg32Sint: - case ast::type::ImageFormat::kRgba32Sint: + case type::ImageFormat::kRgba8Sint: + case type::ImageFormat::kRgba16Sint: + case type::ImageFormat::kR32Sint: + case type::ImageFormat::kRg32Sint: + case type::ImageFormat::kRgba32Sint: return "int4"; default: return nullptr; @@ -226,13 +225,13 @@ std::string GeneratorImpl::current_ep_var_name(VarType type) { } bool GeneratorImpl::EmitConstructedType(std::ostream& out, - const ast::type::Type* ty) { + const type::Type* ty) { make_indent(out); - if (auto* alias = ty->As()) { + if (auto* alias = ty->As()) { // HLSL typedef is for intrinsic types only. For an alias'd struct, // generate a secondary struct with the new name. - if (auto* str = alias->type()->As()) { + if (auto* str = alias->type()->As()) { if (!EmitStructType(out, str, module_->SymbolToName(alias->symbol()))) { return false; } @@ -244,7 +243,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, } out << " " << namer_.NameFor(module_->SymbolToName(alias->symbol())) << ";" << std::endl; - } else if (auto* str = ty->As()) { + } else if (auto* str = ty->As()) { if (!EmitStructType(out, str, module_->SymbolToName(str->symbol()))) { return false; } @@ -385,12 +384,9 @@ bool GeneratorImpl::EmitBinary(std::ostream& pre, // Multiplying by a matrix requires the use of `mul` in order to get the // type of multiply we desire. if (expr->op() == ast::BinaryOp::kMultiply && - ((lhs_type->Is() && - rhs_type->Is()) || - (lhs_type->Is() && - rhs_type->Is()) || - (lhs_type->Is() && - rhs_type->Is()))) { + ((lhs_type->Is() && rhs_type->Is()) || + (lhs_type->Is() && rhs_type->Is()) || + (lhs_type->Is() && rhs_type->Is()))) { out << "mul("; if (!EmitExpression(pre, out, expr->lhs())) { return false; @@ -692,8 +688,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, auto const kNotUsed = ast::intrinsic::TextureSignature::Parameters::kNotUsed; auto* texture = params[pidx.texture]; - auto* texture_type = - texture->result_type()->UnwrapAll()->As(); + auto* texture_type = texture->result_type()->UnwrapAll()->As(); switch (ident->intrinsic()) { case ast::Intrinsic::kTextureDimensions: @@ -708,33 +703,33 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, switch (ident->intrinsic()) { case ast::Intrinsic::kTextureDimensions: switch (texture_type->dim()) { - case ast::type::TextureDimension::kNone: + case type::TextureDimension::kNone: error_ = "texture dimension is kNone"; return false; - case ast::type::TextureDimension::k1d: + case type::TextureDimension::k1d: num_dimensions = 1; break; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: num_dimensions = 2; swizzle = ".x"; break; - case ast::type::TextureDimension::k2d: + case type::TextureDimension::k2d: num_dimensions = 2; break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: num_dimensions = 3; swizzle = ".xy"; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: num_dimensions = 3; break; - case ast::type::TextureDimension::kCube: + case type::TextureDimension::kCube: // width == height == depth for cubes // See https://github.com/gpuweb/gpuweb/issues/1345 num_dimensions = 2; swizzle = ".xyy"; // [width, height, height] break; - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: // width == height == depth for cubes // See https://github.com/gpuweb/gpuweb/issues/1345 num_dimensions = 3; @@ -747,12 +742,12 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, default: error_ = "texture dimension is not arrayed"; return false; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: num_dimensions = 2; swizzle = ".y"; break; - case ast::type::TextureDimension::k2dArray: - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCubeArray: num_dimensions = 3; swizzle = ".z"; break; @@ -764,14 +759,14 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, default: error_ = "texture dimension does not support mips"; return false; - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::kCube: + case type::TextureDimension::k2d: + case type::TextureDimension::kCube: num_dimensions = 3; swizzle = ".z"; break; - case ast::type::TextureDimension::k2dArray: - case ast::type::TextureDimension::k3d: - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: + case type::TextureDimension::k3d: + case type::TextureDimension::kCubeArray: num_dimensions = 4; swizzle = ".w"; break; @@ -782,11 +777,11 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, default: error_ = "texture dimension does not support multisampling"; return false; - case ast::type::TextureDimension::k2d: + case type::TextureDimension::k2d: num_dimensions = 3; swizzle = ".z"; break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: num_dimensions = 4; swizzle = ".w"; break; @@ -864,7 +859,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, break; case ast::Intrinsic::kTextureLoad: out << ".Load("; - if (!texture_type->Is()) { + if (!texture_type->Is()) { pack_mip_in_coords = true; } break; @@ -886,7 +881,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, auto* param_coords = params[pidx.coords]; auto emit_vector_appended_with_i32_zero = [&](tint::ast::Expression* vector) { - auto* i32 = module_->create(); + auto* i32 = module_->create(); ast::SintLiteral zero_lit(Source{}, i32, 0); ast::ScalarConstructorExpression zero(Source{}, &zero_lit); zero.set_result_type(i32); @@ -1063,7 +1058,7 @@ bool GeneratorImpl::EmitScalarConstructor( bool GeneratorImpl::EmitTypeConstructor(std::ostream& pre, std::ostream& out, ast::TypeConstructorExpression* expr) { - if (expr->type()->Is()) { + if (expr->type()->Is()) { out << "{"; } else { if (!EmitType(out, expr->type(), "")) { @@ -1092,7 +1087,7 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& pre, } } - if (expr->type()->Is()) { + if (expr->type()->Is()) { out << "}"; } else { out << ")"; @@ -1379,7 +1374,7 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, return false; } // Array name is output as part of the type - if (!v->type()->Is()) { + if (!v->type()->Is()) { out << " " << module_->SymbolToName(v->symbol()); } } @@ -1447,7 +1442,7 @@ bool GeneratorImpl::EmitEntryPointData( emitted_globals.insert(var->symbol()); auto* type = var->type()->UnwrapIfNeeded(); - if (auto* strct = type->As()) { + if (auto* strct = type->As()) { out << "ConstantBuffer<" << module_->SymbolToName(strct->symbol()) << "> " << module_->SymbolToName(var->symbol()) << " : register(b" << binding->value() << ");" << std::endl; @@ -1490,7 +1485,7 @@ bool GeneratorImpl::EmitEntryPointData( } emitted_globals.insert(var->symbol()); - auto* ac = var->type()->As(); + auto* ac = var->type()->As(); if (ac == nullptr) { error_ = "access control type required for storage buffer"; return false; @@ -1712,18 +1707,18 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) { return true; } -bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) { - if (type->Is()) { +bool GeneratorImpl::EmitZeroValue(std::ostream& out, type::Type* type) { + if (type->Is()) { out << "false"; - } else if (type->Is()) { + } else if (type->Is()) { out << "0.0f"; - } else if (type->Is()) { + } else if (type->Is()) { out << "0"; - } else if (type->Is()) { + } else if (type->Is()) { out << "0u"; - } else if (auto* vec = type->As()) { + } else if (auto* vec = type->As()) { return EmitZeroValue(out, vec->type()); - } else if (auto* mat = type->As()) { + } else if (auto* mat = type->As()) { for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) { if (i != 0) { out << ", "; @@ -1851,7 +1846,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression( first = false; if (auto* mem = expr->As()) { auto* res_type = mem->structure()->result_type()->UnwrapAll(); - if (auto* str = res_type->As()) { + if (auto* str = res_type->As()) { auto* str_type = str->impl(); auto* str_member = str_type->get_member(mem->member()->symbol()); @@ -1861,7 +1856,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression( } out << str_member->offset(); - } else if (res_type->Is()) { + } else if (res_type->Is()) { // TODO(dsinclair): Swizzle stuff // // This must be a single element swizzle if we've got a vector at this @@ -1891,14 +1886,14 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression( auto* ary_type = ary->array()->result_type()->UnwrapAll(); out << "("; - if (auto* arr = ary_type->As()) { + if (auto* arr = ary_type->As()) { out << arr->array_stride(); - } else if (ary_type->Is()) { + } else if (ary_type->Is()) { // TODO(dsinclair): This is a hack. Our vectors can only be f32, i32 // or u32 which are all 4 bytes. When we get f16 or other types we'll // have to ask the type for the byte size. out << "4"; - } else if (auto* mat = ary_type->As()) { + } else if (auto* mat = ary_type->As()) { if (mat->columns() == 2) { out << "8"; } else { @@ -1939,16 +1934,16 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre, bool is_store = rhs != nullptr; std::string access_method = is_store ? "Store" : "Load"; - if (auto* vec = result_type->As()) { + if (auto* vec = result_type->As()) { access_method += std::to_string(vec->size()); - } else if (auto* mat = result_type->As()) { + } else if (auto* mat = result_type->As()) { access_method += std::to_string(mat->rows()); } // If we aren't storing then we need to put in the outer cast. if (!is_store) { if (result_type->is_float_scalar_or_vector() || - result_type->Is()) { + result_type->Is()) { out << "asfloat("; } else if (result_type->is_signed_scalar_or_vector()) { out << "asint("; @@ -1968,7 +1963,7 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre, return false; } - if (auto* mat = result_type->As()) { + if (auto* mat = result_type->As()) { // TODO(dsinclair): This is assuming 4 byte elements. Will need to be fixed // if we get matrixes of f16 or f64. uint32_t stride = mat->rows() == 2 ? 8 : 16; @@ -2056,7 +2051,7 @@ bool GeneratorImpl::is_storage_buffer_access( // // If the data is a multi-element swizzle then we will not load the swizzle // portion through the Load command. - if (data_type->Is() && + if (data_type->Is() && module_->SymbolToName(expr->member()->symbol()).size() > 1) { return false; } @@ -2200,20 +2195,20 @@ bool GeneratorImpl::EmitSwitch(std::ostream& out, ast::SwitchStatement* stmt) { } bool GeneratorImpl::EmitType(std::ostream& out, - ast::type::Type* type, + type::Type* type, const std::string& name) { // HLSL doesn't have the read/write only markings so just unwrap the access // control type. - if (auto* ac = type->As()) { + if (auto* ac = type->As()) { return EmitType(out, ac->type(), name); } - if (auto* alias = type->As()) { + if (auto* alias = type->As()) { out << namer_.NameFor(module_->SymbolToName(alias->symbol())); - } else if (auto* ary = type->As()) { - ast::type::Type* base_type = ary; + } else if (auto* ary = type->As()) { + type::Type* base_type = ary; std::vector sizes; - while (auto* arr = base_type->As()) { + while (auto* arr = base_type->As()) { if (arr->IsRuntimeArray()) { // TODO(dsinclair): Support runtime arrays // https://bugs.chromium.org/p/tint/issues/detail?id=185 @@ -2233,56 +2228,56 @@ bool GeneratorImpl::EmitType(std::ostream& out, for (uint32_t size : sizes) { out << "[" << size << "]"; } - } else if (type->Is()) { + } else if (type->Is()) { out << "bool"; - } else if (type->Is()) { + } else if (type->Is()) { out << "float"; - } else if (type->Is()) { + } else if (type->Is()) { out << "int"; - } else if (auto* mat = type->As()) { + } else if (auto* mat = type->As()) { if (!EmitType(out, mat->type(), "")) { return false; } out << mat->rows() << "x" << mat->columns(); - } else if (type->Is()) { + } else if (type->Is()) { // TODO(dsinclair): What do we do with pointers in HLSL? // https://bugs.chromium.org/p/tint/issues/detail?id=183 error_ = "pointers not supported in HLSL"; return false; - } else if (auto* sampler = type->As()) { + } else if (auto* sampler = type->As()) { out << "Sampler"; if (sampler->IsComparison()) { out << "Comparison"; } out << "State"; - } else if (auto* str = type->As()) { + } else if (auto* str = type->As()) { out << module_->SymbolToName(str->symbol()); - } else if (auto* tex = type->As()) { - if (tex->Is()) { + } else if (auto* tex = type->As()) { + if (tex->Is()) { out << "RW"; } out << "Texture"; switch (tex->dim()) { - case ast::type::TextureDimension::k1d: + case type::TextureDimension::k1d: out << "1D"; break; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: out << "1DArray"; break; - case ast::type::TextureDimension::k2d: + case type::TextureDimension::k2d: out << "2D"; break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out << "2DArray"; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: out << "3D"; break; - case ast::type::TextureDimension::kCube: + case type::TextureDimension::kCube: out << "Cube"; break; - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out << "CubeArray"; break; default: @@ -2290,7 +2285,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, return false; } - if (auto* st = tex->As()) { + if (auto* st = tex->As()) { auto* component = image_format_to_rwtexture_type(st->image_format()); if (component == nullptr) { error_ = "Unsupported StorageTexture ImageFormat: " + @@ -2299,15 +2294,15 @@ bool GeneratorImpl::EmitType(std::ostream& out, } out << "<" << component << ">"; } - } else if (type->Is()) { + } else if (type->Is()) { out << "uint"; - } else if (auto* vec = type->As()) { + } else if (auto* vec = type->As()) { auto size = vec->size(); - if (vec->type()->Is() && size >= 1 && size <= 4) { + if (vec->type()->Is() && size >= 1 && size <= 4) { out << "float" << size; - } else if (vec->type()->Is() && size >= 1 && size <= 4) { + } else if (vec->type()->Is() && size >= 1 && size <= 4) { out << "int" << size; - } else if (vec->type()->Is() && size >= 1 && size <= 4) { + } else if (vec->type()->Is() && size >= 1 && size <= 4) { out << "uint" << size; } else { out << "vector<"; @@ -2316,7 +2311,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } out << ", " << size << ">"; } - } else if (type->Is()) { + } else if (type->Is()) { out << "void"; } else { error_ = "unknown type in EmitType"; @@ -2327,7 +2322,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } bool GeneratorImpl::EmitStructType(std::ostream& out, - const ast::type::Struct* str, + const type::Struct* str, const std::string& name) { // TODO(dsinclair): Block decoration? // if (str->impl()->decoration() != ast::StructDecoration::kNone) { @@ -2344,7 +2339,7 @@ bool GeneratorImpl::EmitStructType(std::ostream& out, return false; } // Array member name will be output with the type - if (!mem->type()->Is()) { + if (!mem->type()->Is()) { out << " " << namer_.NameFor(module_->SymbolToName(mem->symbol())); } out << ";" << std::endl; @@ -2407,7 +2402,7 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { return false; } - if (!var->type()->Is()) { + if (!var->type()->Is()) { out << " " << module_->SymbolToName(var->symbol()); } out << constructor_out.str() << ";" << std::endl; @@ -2464,7 +2459,7 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out, if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { return false; } - if (!var->type()->Is()) { + if (!var->type()->Is()) { out << " " << module_->SymbolToName(var->symbol()); } diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 0044b02067..433c3a1e0c 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -38,10 +38,10 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/struct_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/scope_stack.h" +#include "src/type/struct_type.h" #include "src/writer/hlsl/namer.h" namespace tint { @@ -85,7 +85,7 @@ class GeneratorImpl { /// @param out the output stream /// @param ty the constructed type to generate /// @returns true if the constructed type was emitted - bool EmitConstructedType(std::ostream& out, const ast::type::Type* ty); + bool EmitConstructedType(std::ostream& out, const type::Type* ty); /// Handles an array accessor expression /// @param pre the preamble for the expression stream /// @param out the output of the expression stream @@ -290,16 +290,14 @@ class GeneratorImpl { /// @param type the type to generate /// @param name the name of the variable, only used for array emission /// @returns true if the type is emitted - bool EmitType(std::ostream& out, - ast::type::Type* type, - const std::string& name); + bool EmitType(std::ostream& out, type::Type* type, const std::string& name); /// Handles generating a structure declaration /// @param out the output stream /// @param ty the struct to generate /// @param name the struct name /// @returns true if the struct is emitted bool EmitStructType(std::ostream& out, - const ast::type::Struct* ty, + const type::Struct* ty, const std::string& name); /// Handles a unary op expression /// @param pre the preamble for the expression stream @@ -313,7 +311,7 @@ class GeneratorImpl { /// @param out the output stream /// @param type the type to emit the value for /// @returns true if the zero value was successfully emitted. - bool EmitZeroValue(std::ostream& out, ast::type::Type* type); + bool EmitZeroValue(std::ostream& out, type::Type* type); /// Handles generating a variable /// @param out the output stream /// @param var the variable to generate diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index 544f4eaab2..e04d641307 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -16,7 +16,7 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_array_accessor_test.cc b/src/writer/hlsl/generator_impl_array_accessor_test.cc index fc71b749c0..cb65569fbd 100644 --- a/src/writer/hlsl/generator_impl_array_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_array_accessor_test.cc @@ -19,7 +19,7 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_binary_test.cc b/src/writer/hlsl/generator_impl_binary_test.cc index 457acde5c8..3240c10f90 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -28,16 +28,16 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_bitcast_test.cc b/src/writer/hlsl/generator_impl_bitcast_test.cc index c47df56d73..a6fc90411b 100644 --- a/src/writer/hlsl/generator_impl_bitcast_test.cc +++ b/src/writer/hlsl/generator_impl_bitcast_test.cc @@ -17,9 +17,9 @@ #include "src/ast/bitcast_expression.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_call_test.cc b/src/writer/hlsl/generator_impl_call_test.cc index c9b40b4342..92b19057af 100644 --- a/src/writer/hlsl/generator_impl_call_test.cc +++ b/src/writer/hlsl/generator_impl_call_test.cc @@ -19,7 +19,7 @@ #include "src/ast/function.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/void_type.h" +#include "src/type/void_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_case_test.cc b/src/writer/hlsl/generator_impl_case_test.cc index 23a9a9411b..d6fd89573d 100644 --- a/src/writer/hlsl/generator_impl_case_test.cc +++ b/src/writer/hlsl/generator_impl_case_test.cc @@ -20,7 +20,7 @@ #include "src/ast/identifier_expression.h" #include "src/ast/module.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_cast_test.cc b/src/writer/hlsl/generator_impl_cast_test.cc index 6625755c55..6a8c5334f3 100644 --- a/src/writer/hlsl/generator_impl_cast_test.cc +++ b/src/writer/hlsl/generator_impl_cast_test.cc @@ -16,9 +16,9 @@ #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_constructor_test.cc b/src/writer/hlsl/generator_impl_constructor_test.cc index 55512a433a..0eaeb36a25 100644 --- a/src/writer/hlsl/generator_impl_constructor_test.cc +++ b/src/writer/hlsl/generator_impl_constructor_test.cc @@ -17,15 +17,15 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 70ce1b3923..ee5e40bfb1 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -32,16 +32,16 @@ #include "src/ast/struct.h" #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/hlsl/test_helper.h" @@ -380,7 +380,7 @@ TEST_F(HlslGeneratorImplTest_Function, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ @@ -426,7 +426,7 @@ TEST_F(HlslGeneratorImplTest_Function, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadOnly, s); + type::AccessControl ac(ast::AccessControl::kReadOnly, s); auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ @@ -473,7 +473,7 @@ TEST_F(HlslGeneratorImplTest_Function, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ @@ -773,7 +773,7 @@ void frag_main() { TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_Called_By_EntryPoint_With_StorageBuffer) { - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4()); + type::AccessControl ac(ast::AccessControl::kReadWrite, ty.vec4()); auto* coord_var = Var("coord", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ create(0), @@ -982,7 +982,7 @@ TEST_F(HlslGeneratorImplTest_Function, ast::StructDecorationList{create()}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ diff --git a/src/writer/hlsl/generator_impl_import_test.cc b/src/writer/hlsl/generator_impl_import_test.cc index 04a7785c3a..8b68fcc1ba 100644 --- a/src/writer/hlsl/generator_impl_import_test.cc +++ b/src/writer/hlsl/generator_impl_import_test.cc @@ -22,11 +22,11 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index 2658f740b7..79000d5421 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -15,8 +15,8 @@ #include "src/ast/call_expression.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index e0ec794721..30fab52b57 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -17,9 +17,9 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" #include "src/ast/intrinsic_texture_helper_test.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" #include "src/type_determiner.h" #include "src/writer/hlsl/generator_impl.h" diff --git a/src/writer/hlsl/generator_impl_loop_test.cc b/src/writer/hlsl/generator_impl_loop_test.cc index 4e7f017f22..100e21daba 100644 --- a/src/writer/hlsl/generator_impl_loop_test.cc +++ b/src/writer/hlsl/generator_impl_loop_test.cc @@ -21,9 +21,9 @@ #include "src/ast/loop_statement.h" #include "src/ast/module.h" #include "src/ast/return_statement.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/f32_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index ee8345a611..31211355e0 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -25,10 +25,10 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/hlsl/test_helper.h" @@ -352,10 +352,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, // data.a[2]; // // -> asint(data.Load((2 * 4)); - ast::type::Array ary(ty.i32, 5, - ast::ArrayDecorationList{ - create(4), - }); + type::Array ary(ty.i32, 5, + ast::ArrayDecorationList{ + create(4), + }); auto* str = create( ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})}, @@ -384,10 +384,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, // data.a[(2 + 4) - 3]; // // -> asint(data.Load((4 * ((2 + 4) - 3))); - ast::type::Array ary(ty.i32, 5, - ast::ArrayDecorationList{ - create(4), - }); + type::Array ary(ty.i32, 5, + ast::ArrayDecorationList{ + create(4), + }); auto* str = create( ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})}, @@ -453,10 +453,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, // // -> data.Store((2 * 4), asuint(2.3f)); - ast::type::Array ary(ty.i32, 5, - ast::ArrayDecorationList{ - create(4), - }); + type::Array ary(ty.i32, 5, + ast::ArrayDecorationList{ + create(4), + }); auto* str = create( ast::StructMemberList{Member("a", &ary, {MemberOffset(0)})}, @@ -608,10 +608,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::StructDecorationList{}); auto* data = ty.struct_("Data", data_str); - ast::type::Array ary(data, 4, - ast::ArrayDecorationList{ - create(32), - }); + type::Array ary(data, 4, + ast::ArrayDecorationList{ + create(32), + }); auto* pre_str = create( ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, @@ -657,8 +657,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::StructDecorationList{}); auto* data = ty.struct_("Data", data_str); - ast::type::Array ary( - data, 4, ast::ArrayDecorationList{create(32)}); + type::Array ary(data, 4, + ast::ArrayDecorationList{create(32)}); auto* pre_str = create( ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, @@ -706,10 +706,10 @@ TEST_F( ast::StructDecorationList{}); auto* data = ty.struct_("Data", data_str); - ast::type::Array ary(data, 4, - ast::ArrayDecorationList{ - create(32), - }); + type::Array ary(data, 4, + ast::ArrayDecorationList{ + create(32), + }); auto* pre_str = create( ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, @@ -756,10 +756,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::StructDecorationList{}); auto* data = ty.struct_("Data", data_str); - ast::type::Array ary(data, 4, - ast::ArrayDecorationList{ - create(32), - }); + type::Array ary(data, 4, + ast::ArrayDecorationList{ + create(32), + }); auto* pre_str = create( ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, @@ -806,10 +806,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::StructDecorationList{}); auto* data = ty.struct_("Data", data_str); - ast::type::Array ary(data, 4, - ast::ArrayDecorationList{ - create(32), - }); + type::Array ary(data, 4, + ast::ArrayDecorationList{ + create(32), + }); auto* pre_str = create( ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, @@ -860,10 +860,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, ast::StructDecorationList{}); auto* data = ty.struct_("Data", data_str); - ast::type::Array ary(data, 4, - ast::ArrayDecorationList{ - create(32), - }); + type::Array ary(data, 4, + ast::ArrayDecorationList{ + create(32), + }); auto* pre_str = create( ast::StructMemberList{Member("c", &ary, {MemberOffset(0)})}, diff --git a/src/writer/hlsl/generator_impl_module_constant_test.cc b/src/writer/hlsl/generator_impl_module_constant_test.cc index 171942f9eb..b8ec558aaa 100644 --- a/src/writer/hlsl/generator_impl_module_constant_test.cc +++ b/src/writer/hlsl/generator_impl_module_constant_test.cc @@ -19,8 +19,8 @@ #include "src/ast/float_literal.h" #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_switch_test.cc b/src/writer/hlsl/generator_impl_switch_test.cc index 9a73bceb0b..17d8666c05 100644 --- a/src/writer/hlsl/generator_impl_switch_test.cc +++ b/src/writer/hlsl/generator_impl_switch_test.cc @@ -20,7 +20,7 @@ #include "src/ast/module.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index 44be70a62b..27476aee7e 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -17,7 +17,7 @@ #include "src/ast/function.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/void_type.h" +#include "src/type/void_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 9cf3c4f009..2655b22cfd 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -19,22 +19,22 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { @@ -126,7 +126,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) { // TODO(dsinclair): How to annotate as workgroup? TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Pointer) { - ast::type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); + type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); ASSERT_TRUE(gen.EmitType(out, &p, "")) << gen.error(); EXPECT_EQ(result(), "float*"); @@ -225,21 +225,21 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) { } TEST_F(HlslGeneratorImplTest_Type, EmitSampler) { - ast::type::Sampler sampler(ast::type::SamplerKind::kSampler); + type::Sampler sampler(type::SamplerKind::kSampler); ASSERT_TRUE(gen.EmitType(out, &sampler, "")) << gen.error(); EXPECT_EQ(result(), "SamplerState"); } TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) { - ast::type::Sampler sampler(ast::type::SamplerKind::kComparisonSampler); + type::Sampler sampler(type::SamplerKind::kComparisonSampler); ASSERT_TRUE(gen.EmitType(out, &sampler, "")) << gen.error(); EXPECT_EQ(result(), "SamplerComparisonState"); } struct HlslDepthTextureData { - ast::type::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, HlslDepthTextureData data) { @@ -250,7 +250,7 @@ using HlslDepthtexturesTest = TestParamHelper; TEST_P(HlslDepthtexturesTest, Emit) { auto params = GetParam(); - ast::type::DepthTexture s(params.dim); + type::DepthTexture s(params.dim); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); EXPECT_EQ(result(), params.result); @@ -259,15 +259,15 @@ INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest_Type, HlslDepthtexturesTest, testing::Values( - HlslDepthTextureData{ast::type::TextureDimension::k2d, "Texture2D"}, - HlslDepthTextureData{ast::type::TextureDimension::k2dArray, + HlslDepthTextureData{type::TextureDimension::k2d, "Texture2D"}, + HlslDepthTextureData{type::TextureDimension::k2dArray, "Texture2DArray"}, - HlslDepthTextureData{ast::type::TextureDimension::kCube, "TextureCube"}, - HlslDepthTextureData{ast::type::TextureDimension::kCubeArray, + HlslDepthTextureData{type::TextureDimension::kCube, "TextureCube"}, + HlslDepthTextureData{type::TextureDimension::kCubeArray, "TextureCubeArray"})); struct HlslTextureData { - ast::type::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, HlslTextureData data) { @@ -278,7 +278,7 @@ using HlslSampledtexturesTest = TestParamHelper; TEST_P(HlslSampledtexturesTest, Emit) { auto params = GetParam(); - ast::type::SampledTexture s(params.dim, ty.f32); + type::SampledTexture s(params.dim, ty.f32); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); EXPECT_EQ(result(), params.result); @@ -287,27 +287,25 @@ INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest_Type, HlslSampledtexturesTest, testing::Values( - HlslTextureData{ast::type::TextureDimension::k1d, "Texture1D"}, - HlslTextureData{ast::type::TextureDimension::k1dArray, - "Texture1DArray"}, - HlslTextureData{ast::type::TextureDimension::k2d, "Texture2D"}, - HlslTextureData{ast::type::TextureDimension::k2dArray, - "Texture2DArray"}, - HlslTextureData{ast::type::TextureDimension::k3d, "Texture3D"}, - HlslTextureData{ast::type::TextureDimension::kCube, "TextureCube"}, - HlslTextureData{ast::type::TextureDimension::kCubeArray, + HlslTextureData{type::TextureDimension::k1d, "Texture1D"}, + HlslTextureData{type::TextureDimension::k1dArray, "Texture1DArray"}, + HlslTextureData{type::TextureDimension::k2d, "Texture2D"}, + HlslTextureData{type::TextureDimension::k2dArray, "Texture2DArray"}, + HlslTextureData{type::TextureDimension::k3d, "Texture3D"}, + HlslTextureData{type::TextureDimension::kCube, "TextureCube"}, + HlslTextureData{type::TextureDimension::kCubeArray, "TextureCubeArray"})); TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) { - ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, ty.f32); + type::MultisampledTexture s(type::TextureDimension::k2d, ty.f32); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); EXPECT_EQ(result(), "Texture2D"); } struct HlslStorageTextureData { - ast::type::TextureDimension dim; - ast::type::ImageFormat imgfmt; + type::TextureDimension dim; + type::ImageFormat imgfmt; bool ro; std::string result; }; @@ -320,11 +318,10 @@ using HlslStoragetexturesTest = TestParamHelper; TEST_P(HlslStoragetexturesTest, Emit) { auto params = GetParam(); - ast::type::StorageTexture s(params.dim, - params.imgfmt); - ast::type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly - : ast::AccessControl::kWriteOnly, - &s); + type::StorageTexture s(params.dim, params.imgfmt); + type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly + : ast::AccessControl::kWriteOnly, + &s); ASSERT_TRUE(gen.EmitType(out, &ac, "")) << gen.error(); EXPECT_EQ(result(), params.result); @@ -332,55 +329,54 @@ TEST_P(HlslStoragetexturesTest, Emit) { INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest_Type, HlslStoragetexturesTest, - testing::Values( - HlslStorageTextureData{ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kRgba8Unorm, true, - "RWTexture1D"}, - HlslStorageTextureData{ast::type::TextureDimension::k1dArray, - ast::type::ImageFormat::kRgba8Snorm, true, - "RWTexture1DArray"}, - HlslStorageTextureData{ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kRgba16Float, true, - "RWTexture2D"}, - HlslStorageTextureData{ast::type::TextureDimension::k2dArray, - ast::type::ImageFormat::kR32Float, true, - "RWTexture2DArray"}, - HlslStorageTextureData{ast::type::TextureDimension::k3d, - ast::type::ImageFormat::kRg32Float, true, - "RWTexture3D"}, - HlslStorageTextureData{ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kRgba32Float, false, - "RWTexture1D"}, - HlslStorageTextureData{ast::type::TextureDimension::k1dArray, - ast::type::ImageFormat::kRgba8Uint, false, - "RWTexture1DArray"}, - HlslStorageTextureData{ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kRgba16Uint, false, - "RWTexture2D"}, - HlslStorageTextureData{ast::type::TextureDimension::k2dArray, - ast::type::ImageFormat::kR32Uint, false, - "RWTexture2DArray"}, - HlslStorageTextureData{ast::type::TextureDimension::k3d, - ast::type::ImageFormat::kRg32Uint, false, - "RWTexture3D"}, - HlslStorageTextureData{ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kRgba32Uint, true, - "RWTexture1D"}, - HlslStorageTextureData{ast::type::TextureDimension::k1dArray, - ast::type::ImageFormat::kRgba8Sint, true, - "RWTexture1DArray"}, - HlslStorageTextureData{ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kRgba16Sint, true, - "RWTexture2D"}, - HlslStorageTextureData{ast::type::TextureDimension::k2dArray, - ast::type::ImageFormat::kR32Sint, true, - "RWTexture2DArray"}, - HlslStorageTextureData{ast::type::TextureDimension::k3d, - ast::type::ImageFormat::kRg32Sint, true, - "RWTexture3D"}, - HlslStorageTextureData{ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kRgba32Sint, false, - "RWTexture1D"})); + testing::Values(HlslStorageTextureData{type::TextureDimension::k1d, + type::ImageFormat::kRgba8Unorm, true, + "RWTexture1D"}, + HlslStorageTextureData{type::TextureDimension::k1dArray, + type::ImageFormat::kRgba8Snorm, true, + "RWTexture1DArray"}, + HlslStorageTextureData{type::TextureDimension::k2d, + type::ImageFormat::kRgba16Float, + true, "RWTexture2D"}, + HlslStorageTextureData{type::TextureDimension::k2dArray, + type::ImageFormat::kR32Float, true, + "RWTexture2DArray"}, + HlslStorageTextureData{type::TextureDimension::k3d, + type::ImageFormat::kRg32Float, true, + "RWTexture3D"}, + HlslStorageTextureData{type::TextureDimension::k1d, + type::ImageFormat::kRgba32Float, + false, "RWTexture1D"}, + HlslStorageTextureData{type::TextureDimension::k1dArray, + type::ImageFormat::kRgba8Uint, false, + "RWTexture1DArray"}, + HlslStorageTextureData{type::TextureDimension::k2d, + type::ImageFormat::kRgba16Uint, + false, "RWTexture2D"}, + HlslStorageTextureData{type::TextureDimension::k2dArray, + type::ImageFormat::kR32Uint, false, + "RWTexture2DArray"}, + HlslStorageTextureData{type::TextureDimension::k3d, + type::ImageFormat::kRg32Uint, false, + "RWTexture3D"}, + HlslStorageTextureData{type::TextureDimension::k1d, + type::ImageFormat::kRgba32Uint, true, + "RWTexture1D"}, + HlslStorageTextureData{type::TextureDimension::k1dArray, + type::ImageFormat::kRgba8Sint, true, + "RWTexture1DArray"}, + HlslStorageTextureData{type::TextureDimension::k2d, + type::ImageFormat::kRgba16Sint, true, + "RWTexture2D"}, + HlslStorageTextureData{type::TextureDimension::k2dArray, + type::ImageFormat::kR32Sint, true, + "RWTexture2DArray"}, + HlslStorageTextureData{type::TextureDimension::k3d, + type::ImageFormat::kRg32Sint, true, + "RWTexture3D"}, + HlslStorageTextureData{type::TextureDimension::k1d, + type::ImageFormat::kRgba32Sint, + false, "RWTexture1D"})); } // namespace } // namespace hlsl diff --git a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc index 5d5eae9945..10e62fe3f5 100644 --- a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc @@ -17,12 +17,12 @@ #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/vector_type.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 1de2fb9db9..254ca89f81 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -44,27 +44,27 @@ #include "src/ast/sint_literal.h" #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/access_control_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/float_to_string.h" namespace tint { @@ -167,51 +167,50 @@ bool GeneratorImpl::Generate() { return true; } -uint32_t GeneratorImpl::calculate_largest_alignment(ast::type::Struct* type) { - auto* stct = type->As()->impl(); +uint32_t GeneratorImpl::calculate_largest_alignment(type::Struct* type) { + auto* stct = type->As()->impl(); uint32_t largest_alignment = 0; for (auto* mem : stct->members()) { auto align = calculate_alignment_size(mem->type()); if (align == 0) { return 0; } - if (!mem->type()->Is()) { + if (!mem->type()->Is()) { largest_alignment = std::max(largest_alignment, align); } else { largest_alignment = std::max( largest_alignment, - calculate_largest_alignment(mem->type()->As())); + calculate_largest_alignment(mem->type()->As())); } } return largest_alignment; } -uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { - if (auto* alias = type->As()) { +uint32_t GeneratorImpl::calculate_alignment_size(type::Type* type) { + if (auto* alias = type->As()) { return calculate_alignment_size(alias->type()); } - if (auto* ary = type->As()) { + if (auto* ary = type->As()) { // TODO(dsinclair): Handle array stride and adjust for alignment. uint32_t type_size = calculate_alignment_size(ary->type()); return ary->size() * type_size; } - if (type->Is()) { + if (type->Is()) { return 1; } - if (type->Is()) { + if (type->Is()) { return 0; } - if (type->Is() || type->Is() || - type->Is()) { + if (type->Is() || type->Is() || type->Is()) { return 4; } - if (auto* mat = type->As()) { + if (auto* mat = type->As()) { // TODO(dsinclair): Handle MatrixStride // https://github.com/gpuweb/gpuweb/issues/773 uint32_t type_size = calculate_alignment_size(mat->type()); return mat->rows() * mat->columns() * type_size; } - if (auto* stct_ty = type->As()) { + if (auto* stct_ty = type->As()) { auto* stct = stct_ty->impl(); uint32_t count = 0; uint32_t largest_alignment = 0; @@ -226,7 +225,7 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { if (align == 0) { return 0; } - if (auto* str = mem->type()->As()) { + if (auto* str = mem->type()->As()) { largest_alignment = std::max(largest_alignment, calculate_largest_alignment(str)); } else { @@ -241,7 +240,7 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { count = adjust_for_alignment(count, largest_alignment); return count; } - if (auto* vec = type->As()) { + if (auto* vec = type->As()) { uint32_t type_size = calculate_alignment_size(vec->type()); if (vec->size() == 2) { return 2 * type_size; @@ -251,17 +250,17 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) { return 0; } -bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) { +bool GeneratorImpl::EmitConstructedType(const type::Type* ty) { make_indent(); - if (auto* alias = ty->As()) { + if (auto* alias = ty->As()) { out_ << "typedef "; if (!EmitType(alias->type(), "")) { return false; } out_ << " " << namer_.NameFor(module_->SymbolToName(alias->symbol())) << ";" << std::endl; - } else if (auto* str = ty->As()) { + } else if (auto* str = ty->As()) { if (!EmitStructType(str)) { return false; } @@ -611,31 +610,29 @@ bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) { auto const kNotUsed = ast::intrinsic::TextureSignature::Parameters::kNotUsed; assert(pidx.texture != kNotUsed); - auto* texture_type = params[pidx.texture] - ->result_type() - ->UnwrapAll() - ->As(); + auto* texture_type = + params[pidx.texture]->result_type()->UnwrapAll()->As(); switch (ident->intrinsic()) { case ast::Intrinsic::kTextureDimensions: { std::vector dims; switch (texture_type->dim()) { - case ast::type::TextureDimension::kNone: + case type::TextureDimension::kNone: error_ = "texture dimension is kNone"; return false; - case ast::type::TextureDimension::k1d: - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1d: + case type::TextureDimension::k1dArray: dims = {"width"}; break; - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: dims = {"width", "height"}; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: dims = {"width", "height", "depth"}; break; - case ast::type::TextureDimension::kCube: - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: // width == height == depth for cubes // See https://github.com/gpuweb/gpuweb/issues/1345 dims = {"width", "height", "height"}; @@ -768,20 +765,20 @@ bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) { auto dim = params[pidx.texture] ->result_type() ->UnwrapPtrIfNeeded() - ->As() + ->As() ->dim(); switch (dim) { - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: maybe_write_comma(); out_ << "gradient2d("; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: maybe_write_comma(); out_ << "gradient3d("; break; - case ast::type::TextureDimension::kCube: - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: maybe_write_comma(); out_ << "gradientcube("; break; @@ -853,26 +850,26 @@ std::string GeneratorImpl::generate_builtin_name( out += module_->SymbolToName(ident->symbol()); break; case ast::Intrinsic::kAbs: - if (ident->result_type()->Is()) { + if (ident->result_type()->Is()) { out += "fabs"; - } else if (ident->result_type()->Is() || - ident->result_type()->Is()) { + } else if (ident->result_type()->Is() || + ident->result_type()->Is()) { out += "abs"; } break; case ast::Intrinsic::kMax: - if (ident->result_type()->Is()) { + if (ident->result_type()->Is()) { out += "fmax"; - } else if (ident->result_type()->Is() || - ident->result_type()->Is()) { + } else if (ident->result_type()->Is() || + ident->result_type()->Is()) { out += "max"; } break; case ast::Intrinsic::kMin: - if (ident->result_type()->Is()) { + if (ident->result_type()->Is()) { out += "fmin"; - } else if (ident->result_type()->Is() || - ident->result_type()->Is()) { + } else if (ident->result_type()->Is() || + ident->result_type()->Is()) { out += "min"; } break; @@ -951,7 +948,7 @@ bool GeneratorImpl::EmitContinue(ast::ContinueStatement*) { } bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { - if (expr->type()->Is()) { + if (expr->type()->Is()) { out_ << "{"; } else { if (!EmitType(expr->type(), "")) { @@ -980,7 +977,7 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { } } - if (expr->type()->Is()) { + if (expr->type()->Is()) { out_ << "}"; } else { out_ << ")"; @@ -988,26 +985,26 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) { return true; } -bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) { - if (type->Is()) { +bool GeneratorImpl::EmitZeroValue(type::Type* type) { + if (type->Is()) { out_ << "false"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "0.0f"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "0"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "0u"; - } else if (auto* vec = type->As()) { + } else if (auto* vec = type->As()) { return EmitZeroValue(vec->type()); - } else if (auto* mat = type->As()) { + } else if (auto* mat = type->As()) { return EmitZeroValue(mat->type()); - } else if (auto* arr = type->As()) { + } else if (auto* arr = type->As()) { out_ << "{"; if (!EmitZeroValue(arr->type())) { return false; } out_ << "}"; - } else if (type->As()) { + } else if (type->As()) { out_ << "{}"; } else { error_ = "Invalid type for zero emission: " + type->type_name(); @@ -1348,7 +1345,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, } first = false; - auto* ac = var->type()->As(); + auto* ac = var->type()->As(); if (ac == nullptr) { error_ = "invalid type for storage buffer, expected access control"; return false; @@ -1374,7 +1371,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, return false; } // Array name is output as part of the type - if (!v->type()->Is()) { + if (!v->type()->Is()) { out_ << " " << module_->SymbolToName(v->symbol()); } } @@ -1512,7 +1509,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto* binding = data.second.binding; // auto* set = data.second.set; - auto* ac = var->type()->As(); + auto* ac = var->type()->As(); if (ac == nullptr) { error_ = "invalid type for storage buffer, expected access control"; return false; @@ -1864,9 +1861,9 @@ bool GeneratorImpl::EmitSwitch(ast::SwitchStatement* stmt) { return true; } -bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { +bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) { std::string access_str = ""; - if (auto* ac = type->As()) { + if (auto* ac = type->As()) { if (ac->access_control() == ast::AccessControl::kReadOnly) { access_str = "read"; } else if (ac->access_control() == ast::AccessControl::kWriteOnly) { @@ -1879,12 +1876,12 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { type = ac->type(); } - if (auto* alias = type->As()) { + if (auto* alias = type->As()) { out_ << namer_.NameFor(module_->SymbolToName(alias->symbol())); - } else if (auto* ary = type->As()) { - ast::type::Type* base_type = ary; + } else if (auto* ary = type->As()) { + type::Type* base_type = ary; std::vector sizes; - while (auto* arr = base_type->As()) { + while (auto* arr = base_type->As()) { if (arr->IsRuntimeArray()) { sizes.push_back(1); } else { @@ -1901,79 +1898,79 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { for (uint32_t size : sizes) { out_ << "[" << size << "]"; } - } else if (type->Is()) { + } else if (type->Is()) { out_ << "bool"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "float"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "int"; - } else if (auto* mat = type->As()) { + } else if (auto* mat = type->As()) { if (!EmitType(mat->type(), "")) { return false; } out_ << mat->columns() << "x" << mat->rows(); - } else if (auto* ptr = type->As()) { + } else if (auto* ptr = type->As()) { // TODO(dsinclair): Storage class? if (!EmitType(ptr->type(), "")) { return false; } out_ << "*"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "sampler"; - } else if (auto* str = type->As()) { + } else if (auto* str = type->As()) { // The struct type emits as just the name. The declaration would be emitted // as part of emitting the constructed types. out_ << module_->SymbolToName(str->symbol()); - } else if (auto* tex = type->As()) { - if (tex->Is()) { + } else if (auto* tex = type->As()) { + if (tex->Is()) { out_ << "depth"; } else { out_ << "texture"; } switch (tex->dim()) { - case ast::type::TextureDimension::k1d: + case type::TextureDimension::k1d: out_ << "1d"; break; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: out_ << "1d_array"; break; - case ast::type::TextureDimension::k2d: + case type::TextureDimension::k2d: out_ << "2d"; break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out_ << "2d_array"; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: out_ << "3d"; break; - case ast::type::TextureDimension::kCube: + case type::TextureDimension::kCube: out_ << "cube"; break; - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out_ << "cube_array"; break; default: error_ = "Invalid texture dimensions"; return false; } - if (tex->Is()) { + if (tex->Is()) { out_ << "_ms"; } out_ << "<"; - if (tex->Is()) { + if (tex->Is()) { out_ << "float, access::sample"; - } else if (auto* storage = tex->As()) { + } else if (auto* storage = tex->As()) { if (!EmitType(storage->type(), "")) { return false; } out_ << ", access::" << access_str; - } else if (auto* ms = tex->As()) { + } else if (auto* ms = tex->As()) { if (!EmitType(ms->type(), "")) { return false; } out_ << ", access::sample"; - } else if (auto* sampled = tex->As()) { + } else if (auto* sampled = tex->As()) { if (!EmitType(sampled->type(), "")) { return false; } @@ -1984,14 +1981,14 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { } out_ << ">"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "uint"; - } else if (auto* vec = type->As()) { + } else if (auto* vec = type->As()) { if (!EmitType(vec->type(), "")) { return false; } out_ << vec->size(); - } else if (type->Is()) { + } else if (type->Is()) { out_ << "void"; } else { error_ = "unknown type in EmitType: " + type->type_name(); @@ -2001,7 +1998,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { return true; } -bool GeneratorImpl::EmitStructType(const ast::type::Struct* str) { +bool GeneratorImpl::EmitStructType(const type::Struct* str) { // TODO(dsinclair): Block decoration? // if (str->impl()->decoration() != ast::StructDecoration::kNone) { // } @@ -2040,7 +2037,7 @@ bool GeneratorImpl::EmitStructType(const ast::type::Struct* str) { current_offset += size; // Array member name will be output with the type - if (!mem->type()->Is()) { + if (!mem->type()->Is()) { out_ << " " << namer_.NameFor(module_->SymbolToName(mem->symbol())); } out_ << ";" << std::endl; @@ -2086,7 +2083,7 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var, bool skip_constructor) { if (!EmitType(var->type(), module_->SymbolToName(var->symbol()))) { return false; } - if (!var->type()->Is()) { + if (!var->type()->Is()) { out_ << " " << module_->SymbolToName(var->symbol()); } @@ -2128,7 +2125,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { if (!EmitType(var->type(), module_->SymbolToName(var->symbol()))) { return false; } - if (!var->type()->Is()) { + if (!var->type()->Is()) { out_ << " " << module_->SymbolToName(var->symbol()); } diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index 63ff18649e..95b6109a2d 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -39,10 +39,10 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/struct_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/scope_stack.h" +#include "src/type/struct_type.h" #include "src/writer/msl/namer.h" #include "src/writer/text_generator.h" @@ -65,16 +65,16 @@ class GeneratorImpl : public TextGenerator { /// for pointers as the size is unknown. /// @param type the type to calculate the alignment size for /// @returns the number of bytes used to align `type` or 0 on error - uint32_t calculate_alignment_size(ast::type::Type* type); + uint32_t calculate_alignment_size(type::Type* type); /// Calculates the largest alignment seen within a struct /// @param type the struct to calculate /// @returns the largest alignment value - uint32_t calculate_largest_alignment(ast::type::Struct* type); + uint32_t calculate_largest_alignment(type::Struct* type); /// Handles generating a constructed /// @param ty the constructed type to generate /// @returns true if the constructed type was emitted - bool EmitConstructedType(const ast::type::Type* ty); + bool EmitConstructedType(const type::Type* ty); /// Handles an array accessor expression /// @param expr the expression to emit /// @returns true if the array accessor was emitted @@ -204,11 +204,11 @@ class GeneratorImpl : public TextGenerator { /// @param type the type to generate /// @param name the name of the variable, only used for array emission /// @returns true if the type is emitted - bool EmitType(ast::type::Type* type, const std::string& name); + bool EmitType(type::Type* type, const std::string& name); /// Handles generating a struct declaration /// @param str the struct to generate /// @returns true if the struct is emitted - bool EmitStructType(const ast::type::Struct* str); + bool EmitStructType(const type::Struct* str); /// Handles emitting a type constructor /// @param expr the type constructor expression /// @returns true if the constructor is emitted @@ -229,7 +229,7 @@ class GeneratorImpl : public TextGenerator { /// Emits the zero value for the given type /// @param type the type to emit the value for /// @returns true if the zero value was successfully emitted. - bool EmitZeroValue(ast::type::Type* type); + bool EmitZeroValue(type::Type* type); /// Determines if the function needs the input struct passed to it. /// @param func the function to check diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index b22aa7471c..0648d20238 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -16,7 +16,7 @@ #include "src/ast/module.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_array_accessor_test.cc b/src/writer/msl/generator_impl_array_accessor_test.cc index 5b5c54d626..9f8cda662b 100644 --- a/src/writer/msl/generator_impl_array_accessor_test.cc +++ b/src/writer/msl/generator_impl_array_accessor_test.cc @@ -20,7 +20,7 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_bitcast_test.cc b/src/writer/msl/generator_impl_bitcast_test.cc index de56fd8967..372a889969 100644 --- a/src/writer/msl/generator_impl_bitcast_test.cc +++ b/src/writer/msl/generator_impl_bitcast_test.cc @@ -18,7 +18,7 @@ #include "src/ast/bitcast_expression.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/f32_type.h" +#include "src/type/f32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index 3b7c9edb3d..6df0f198e2 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -20,7 +20,7 @@ #include "src/ast/function.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/void_type.h" +#include "src/type/void_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index dd19fcc072..a37f33ebeb 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -21,7 +21,7 @@ #include "src/ast/identifier_expression.h" #include "src/ast/module.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_cast_test.cc b/src/writer/msl/generator_impl_cast_test.cc index 3713b86763..13779876ed 100644 --- a/src/writer/msl/generator_impl_cast_test.cc +++ b/src/writer/msl/generator_impl_cast_test.cc @@ -17,9 +17,9 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_constructor_test.cc b/src/writer/msl/generator_impl_constructor_test.cc index ff82185c22..aa38874b84 100644 --- a/src/writer/msl/generator_impl_constructor_test.cc +++ b/src/writer/msl/generator_impl_constructor_test.cc @@ -18,15 +18,15 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" @@ -117,7 +117,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) { } TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) { - ast::type::Array ary(ty.vec3(), 3, ast::ArrayDecorationList{}); + type::Array ary(ty.vec3(), 3, ast::ArrayDecorationList{}); ast::ExpressionList ary_values; diff --git a/src/writer/msl/generator_impl_function_entry_point_data_test.cc b/src/writer/msl/generator_impl_function_entry_point_data_test.cc index 461035b0bd..dbe62b99c9 100644 --- a/src/writer/msl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/msl/generator_impl_function_entry_point_data_test.cc @@ -22,11 +22,11 @@ #include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/stage_decoration.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 53b80eca18..0ad50d3346 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -35,15 +35,15 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" @@ -329,7 +329,7 @@ TEST_F(MslGeneratorImplTest, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); mod->AddConstructedType(s); @@ -382,7 +382,7 @@ TEST_F(MslGeneratorImplTest, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadOnly, s); + type::AccessControl ac(ast::AccessControl::kReadOnly, s); mod->AddConstructedType(s); auto* coord_var = @@ -687,7 +687,7 @@ TEST_F(MslGeneratorImplTest, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); mod->AddConstructedType(s); auto* coord_var = @@ -754,7 +754,7 @@ TEST_F(MslGeneratorImplTest, ast::StructDecorationList{}); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadOnly, s); + type::AccessControl ac(ast::AccessControl::kReadOnly, s); mod->AddConstructedType(s); auto* coord_var = @@ -933,7 +933,7 @@ TEST_F(MslGeneratorImplTest, ast::StructMemberList{Member("d", ty.f32, {MemberOffset(0)})}, s_decos); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr, diff --git a/src/writer/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc index b7d97d6d34..e1233313ba 100644 --- a/src/writer/msl/generator_impl_import_test.cc +++ b/src/writer/msl/generator_impl_import_test.cc @@ -23,11 +23,11 @@ #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc index b1f0e92b00..41fa96e12d 100644 --- a/src/writer/msl/generator_impl_intrinsic_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_test.cc @@ -16,8 +16,8 @@ #include "src/ast/call_expression.h" #include "src/ast/identifier_expression.h" #include "src/ast/module.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_intrinsic_texture_test.cc b/src/writer/msl/generator_impl_intrinsic_texture_test.cc index 54c2a9ef46..47676262e2 100644 --- a/src/writer/msl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_texture_test.cc @@ -17,9 +17,9 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" #include "src/ast/intrinsic_texture_helper_test.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc index 76e8a3e2f1..d7f13abdfd 100644 --- a/src/writer/msl/generator_impl_loop_test.cc +++ b/src/writer/msl/generator_impl_loop_test.cc @@ -22,9 +22,9 @@ #include "src/ast/loop_statement.h" #include "src/ast/module.h" #include "src/ast/return_statement.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/f32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_module_constant_test.cc b/src/writer/msl/generator_impl_module_constant_test.cc index 7e272d6aa8..d251dc60f2 100644 --- a/src/writer/msl/generator_impl_module_constant_test.cc +++ b/src/writer/msl/generator_impl_module_constant_test.cc @@ -20,8 +20,8 @@ #include "src/ast/float_literal.h" #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/writer/msl/generator_impl.h" diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index c67822ae0b..8123138b40 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -21,7 +21,7 @@ #include "src/ast/module.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index c73e148df7..69de899233 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -26,17 +26,17 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/msl/namer.h" #include "src/writer/msl/test_helper.h" @@ -137,7 +137,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_matrix) { } TEST_F(MslGeneratorImplTest, calculate_alignment_size_pointer) { - ast::type::Pointer ptr(ty.bool_, ast::StorageClass::kPrivate); + type::Pointer ptr(ty.bool_, ast::StorageClass::kPrivate); EXPECT_EQ(0u, gen.calculate_alignment_size(&ptr)); } @@ -187,7 +187,7 @@ using MslVectorSizeBoolTest = TestParamHelper; TEST_P(MslVectorSizeBoolTest, calculate) { auto param = GetParam(); - ast::type::Vector vec(ty.bool_, param.elements); + type::Vector vec(ty.bool_, param.elements); EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec)); } INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, @@ -200,7 +200,7 @@ using MslVectorSizeI32Test = TestParamHelper; TEST_P(MslVectorSizeI32Test, calculate) { auto param = GetParam(); - ast::type::Vector vec(ty.i32, param.elements); + type::Vector vec(ty.i32, param.elements); EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec)); } INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, @@ -213,7 +213,7 @@ using MslVectorSizeU32Test = TestParamHelper; TEST_P(MslVectorSizeU32Test, calculate) { auto param = GetParam(); - ast::type::Vector vec(ty.u32, param.elements); + type::Vector vec(ty.u32, param.elements); EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec)); } INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, @@ -226,7 +226,7 @@ using MslVectorSizeF32Test = TestParamHelper; TEST_P(MslVectorSizeF32Test, calculate) { auto param = GetParam(); - ast::type::Vector vec(ty.f32, param.elements); + type::Vector vec(ty.f32, param.elements); EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec)); } INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest, diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index 90c3c8819b..8bc114612e 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -20,22 +20,22 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" @@ -131,7 +131,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Matrix) { // TODO(dsinclair): How to annotate as workgroup? TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Pointer) { - ast::type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); + type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); ASSERT_TRUE(gen.EmitType(&p, "")) << gen.error(); EXPECT_EQ(gen.result(), "float*"); @@ -233,21 +233,21 @@ TEST_F(MslGeneratorImplTest, EmitType_Void) { } TEST_F(MslGeneratorImplTest, EmitType_Sampler) { - ast::type::Sampler sampler(ast::type::SamplerKind::kSampler); + type::Sampler sampler(type::SamplerKind::kSampler); ASSERT_TRUE(gen.EmitType(&sampler, "")) << gen.error(); EXPECT_EQ(gen.result(), "sampler"); } TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) { - ast::type::Sampler sampler(ast::type::SamplerKind::kComparisonSampler); + type::Sampler sampler(type::SamplerKind::kComparisonSampler); ASSERT_TRUE(gen.EmitType(&sampler, "")) << gen.error(); EXPECT_EQ(gen.result(), "sampler"); } struct MslDepthTextureData { - ast::type::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, MslDepthTextureData data) { @@ -258,7 +258,7 @@ using MslDepthTexturesTest = TestParamHelper; TEST_P(MslDepthTexturesTest, Emit) { auto params = GetParam(); - ast::type::DepthTexture s(params.dim); + type::DepthTexture s(params.dim); ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error(); EXPECT_EQ(gen.result(), params.result); @@ -266,18 +266,18 @@ TEST_P(MslDepthTexturesTest, Emit) { INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslDepthTexturesTest, - testing::Values(MslDepthTextureData{ast::type::TextureDimension::k2d, + testing::Values(MslDepthTextureData{type::TextureDimension::k2d, "depth2d"}, - MslDepthTextureData{ast::type::TextureDimension::k2dArray, + MslDepthTextureData{type::TextureDimension::k2dArray, "depth2d_array"}, - MslDepthTextureData{ast::type::TextureDimension::kCube, + MslDepthTextureData{type::TextureDimension::kCube, "depthcube"}, MslDepthTextureData{ - ast::type::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, "depthcube_array"})); struct MslTextureData { - ast::type::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, MslTextureData data) { @@ -288,7 +288,7 @@ using MslSampledtexturesTest = TestParamHelper; TEST_P(MslSampledtexturesTest, Emit) { auto params = GetParam(); - ast::type::SampledTexture s(params.dim, ty.f32); + type::SampledTexture s(params.dim, ty.f32); ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error(); EXPECT_EQ(gen.result(), params.result); @@ -296,31 +296,31 @@ TEST_P(MslSampledtexturesTest, Emit) { INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslSampledtexturesTest, - testing::Values(MslTextureData{ast::type::TextureDimension::k1d, + testing::Values(MslTextureData{type::TextureDimension::k1d, "texture1d"}, - MslTextureData{ast::type::TextureDimension::k1dArray, + MslTextureData{type::TextureDimension::k1dArray, "texture1d_array"}, - MslTextureData{ast::type::TextureDimension::k2d, + MslTextureData{type::TextureDimension::k2d, "texture2d"}, - MslTextureData{ast::type::TextureDimension::k2dArray, + MslTextureData{type::TextureDimension::k2dArray, "texture2d_array"}, - MslTextureData{ast::type::TextureDimension::k3d, + MslTextureData{type::TextureDimension::k3d, "texture3d"}, - MslTextureData{ast::type::TextureDimension::kCube, + MslTextureData{type::TextureDimension::kCube, "texturecube"}, MslTextureData{ - ast::type::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, "texturecube_array"})); TEST_F(MslGeneratorImplTest, Emit_TypeMultisampledTexture) { - ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, ty.u32); + type::MultisampledTexture s(type::TextureDimension::k2d, ty.u32); ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error(); EXPECT_EQ(gen.result(), "texture2d_ms"); } struct MslStorageTextureData { - ast::type::TextureDimension dim; + type::TextureDimension dim; bool ro; std::string result; }; @@ -332,11 +332,10 @@ using MslStorageTexturesTest = TestParamHelper; TEST_P(MslStorageTexturesTest, Emit) { auto params = GetParam(); - ast::type::StorageTexture s(params.dim, - ast::type::ImageFormat::kR16Float); - ast::type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly - : ast::AccessControl::kWriteOnly, - &s); + type::StorageTexture s(params.dim, type::ImageFormat::kR16Float); + type::AccessControl ac(params.ro ? ast::AccessControl::kReadOnly + : ast::AccessControl::kWriteOnly, + &s); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(gen.EmitType(&ac, "")) << gen.error(); @@ -346,25 +345,25 @@ INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslStorageTexturesTest, testing::Values( - MslStorageTextureData{ast::type::TextureDimension::k1d, true, + MslStorageTextureData{type::TextureDimension::k1d, true, "texture1d"}, - MslStorageTextureData{ast::type::TextureDimension::k1dArray, true, + MslStorageTextureData{type::TextureDimension::k1dArray, true, "texture1d_array"}, - MslStorageTextureData{ast::type::TextureDimension::k2d, true, + MslStorageTextureData{type::TextureDimension::k2d, true, "texture2d"}, - MslStorageTextureData{ast::type::TextureDimension::k2dArray, true, + MslStorageTextureData{type::TextureDimension::k2dArray, true, "texture2d_array"}, - MslStorageTextureData{ast::type::TextureDimension::k3d, true, + MslStorageTextureData{type::TextureDimension::k3d, true, "texture3d"}, - MslStorageTextureData{ast::type::TextureDimension::k1d, false, + MslStorageTextureData{type::TextureDimension::k1d, false, "texture1d"}, - MslStorageTextureData{ast::type::TextureDimension::k1dArray, false, + MslStorageTextureData{type::TextureDimension::k1dArray, false, "texture1d_array"}, - MslStorageTextureData{ast::type::TextureDimension::k2d, false, + MslStorageTextureData{type::TextureDimension::k2d, false, "texture2d"}, - MslStorageTextureData{ast::type::TextureDimension::k2dArray, false, + MslStorageTextureData{type::TextureDimension::k2dArray, false, "texture2d_array"}, - MslStorageTextureData{ast::type::TextureDimension::k3d, false, + MslStorageTextureData{type::TextureDimension::k3d, false, "texture3d"})); } // namespace diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index 777bb3254d..3da40f8158 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -23,13 +23,13 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" @@ -61,7 +61,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) { - ast::type::Array ary(ty.f32, 5, ast::ArrayDecorationList{}); + type::Array ary(ty.f32, 5, ast::ArrayDecorationList{}); auto* var = Var("a", ast::StorageClass::kNone, &ary); auto* stmt = create(var); diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 26212e6327..bfd42d7179 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -52,27 +52,27 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/append_vector.h" namespace tint { @@ -152,15 +152,14 @@ uint32_t IndexFromName(char name) { /// one or more levels of an arrays inside of `type`. /// @param type the given type, which must not be null /// @returns the nested matrix type, or nullptr if none -ast::type::Matrix* GetNestedMatrixType(ast::type::Type* type) { - while (auto* arr = type->As()) { +type::Matrix* GetNestedMatrixType(type::Type* type) { + while (auto* arr = type->As()) { type = arr->type(); } - return type->As(); + return type->As(); } -uint32_t intrinsic_to_glsl_method(ast::type::Type* type, - ast::Intrinsic intrinsic) { +uint32_t intrinsic_to_glsl_method(type::Type* type, ast::Intrinsic intrinsic) { switch (intrinsic) { case ast::Intrinsic::kAbs: if (type->is_float_scalar_or_vector()) { @@ -273,8 +272,8 @@ uint32_t intrinsic_to_glsl_method(ast::type::Type* type, } /// @return the vector element type if ty is a vector, otherwise return ty. -ast::type::Type* ElementTypeOf(ast::type::Type* ty) { - if (auto* v = ty->As()) { +type::Type* ElementTypeOf(type::Type* ty) { + if (auto* v = ty->As()) { return v->type(); } return ty; @@ -386,7 +385,7 @@ bool Builder::GenerateLabel(uint32_t id) { } uint32_t Builder::GenerateU32Literal(uint32_t val) { - ast::type::U32 u32; + type::U32 u32; ast::SintLiteral lit(Source{}, &u32, val); return GenerateLiteralIfNeeded(nullptr, &lit); } @@ -651,7 +650,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) { auto result = result_op(); auto var_id = result.to_i(); auto sc = ast::StorageClass::kFunction; - ast::type::Pointer pt(var->type(), sc); + type::Pointer pt(var->type(), sc); auto type_id = GenerateTypeIfNeeded(&pt); if (type_id == 0) { return false; @@ -725,7 +724,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { ? ast::StorageClass::kPrivate : var->storage_class(); - ast::type::Pointer pt(var->type(), sc); + type::Pointer pt(var->type(), sc); auto type_id = GenerateTypeIfNeeded(&pt); if (type_id == 0) { return false; @@ -743,8 +742,8 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { auto* type = var->type()->UnwrapAll(); if (var->has_constructor()) { ops.push_back(Operand::Int(init_id)); - } else if (type->Is()) { - if (auto* ac = var->type()->As()) { + } else if (type->Is()) { + if (auto* ac = var->type()->As()) { switch (ac->access_control()) { case ast::AccessControl::kWriteOnly: push_annot( @@ -760,7 +759,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { break; } } - } else if (!type->Is()) { + } else if (!type->Is()) { // Certain cases require us to generate a constructor value. // // 1- ConstantId's must be attached to the OpConstant, if we have a @@ -769,16 +768,16 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { // 2- If we don't have a constructor and we're an Output or Private variable // then WGSL requires an initializer. if (var->HasConstantIdDecoration()) { - if (type->Is()) { + if (type->Is()) { ast::FloatLiteral l(Source{}, type, 0.0f); init_id = GenerateLiteralIfNeeded(var, &l); - } else if (type->Is()) { + } else if (type->Is()) { ast::UintLiteral l(Source{}, type, 0); init_id = GenerateLiteralIfNeeded(var, &l); - } else if (type->Is()) { + } else if (type->Is()) { ast::SintLiteral l(Source{}, type, 0); init_id = GenerateLiteralIfNeeded(var, &l); - } else if (type->Is()) { + } else if (type->Is()) { ast::BoolLiteral l(Source{}, type, false); init_id = GenerateLiteralIfNeeded(var, &l); } else { @@ -843,9 +842,9 @@ bool Builder::GenerateArrayAccessor(ast::ArrayAccessorExpression* expr, // If the source is a pointer we access chain into it. We also access chain // into an array of non-scalar types. - if (info->source_type->Is() || - (info->source_type->Is() && - !info->source_type->As()->type()->is_scalar())) { + if (info->source_type->Is() || + (info->source_type->Is() && + !info->source_type->As()->type()->is_scalar())) { info->access_chain_indices.push_back(idx_id); info->source_type = expr->result_type(); return true; @@ -880,15 +879,15 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr, // If the data_type is a structure we're accessing a member, if it's a // vector we're accessing a swizzle. - if (data_type->Is()) { - if (!info->source_type->Is()) { + if (data_type->Is()) { + if (!info->source_type->Is()) { error_ = "Attempting to access a struct member on a non-pointer. Something is " "wrong"; return false; } - auto* strct = data_type->As()->impl(); + auto* strct = data_type->As()->impl(); auto symbol = expr->member()->symbol(); uint32_t i = 0; @@ -908,7 +907,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr, return true; } - if (!data_type->Is()) { + if (!data_type->Is()) { error_ = "Member accessor without a struct or vector. Something is wrong"; return false; } @@ -923,7 +922,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr, return false; } - if (info->source_type->Is()) { + if (info->source_type->Is()) { auto idx_id = GenerateU32Literal(val); if (idx_id == 0) { return 0; @@ -1044,10 +1043,10 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) { if (auto* array = accessors[0]->As()) { auto* ary_res_type = array->array()->result_type(); - if (!ary_res_type->Is() && - (ary_res_type->Is() && - !ary_res_type->As()->type()->is_scalar())) { - ast::type::Pointer ptr(ary_res_type, ast::StorageClass::kFunction); + if (!ary_res_type->Is() && + (ary_res_type->Is() && + !ary_res_type->As()->type()->is_scalar())) { + type::Pointer ptr(ary_res_type, ast::StorageClass::kFunction); auto result_type_id = GenerateTypeIfNeeded(&ptr); if (result_type_id == 0) { return 0; @@ -1126,8 +1125,8 @@ uint32_t Builder::GenerateIdentifierExpression( return 0; } -uint32_t Builder::GenerateLoadIfNeeded(ast::type::Type* type, uint32_t id) { - if (!type->Is()) { +uint32_t Builder::GenerateLoadIfNeeded(type::Type* type, uint32_t id) { + if (!type->Is()) { return id; } @@ -1237,7 +1236,7 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) { } auto* sc = e->As(); - if (result_type->Is() && sc == nullptr) { + if (result_type->Is() && sc == nullptr) { return false; } @@ -1246,14 +1245,14 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) { continue; } - ast::type::Type* subtype = result_type->UnwrapAll(); - if (auto* vec = subtype->As()) { + type::Type* subtype = result_type->UnwrapAll(); + if (auto* vec = subtype->As()) { subtype = vec->type()->UnwrapAll(); - } else if (auto* mat = subtype->As()) { + } else if (auto* mat = subtype->As()) { subtype = mat->type()->UnwrapAll(); - } else if (auto* arr = subtype->As()) { + } else if (auto* arr = subtype->As()) { subtype = arr->type()->UnwrapAll(); - } else if (auto* str = subtype->As()) { + } else if (auto* str = subtype->As()) { subtype = str->impl()->members()[i]->type()->UnwrapAll(); } if (subtype != sc->result_type()->UnwrapAll()) { @@ -1285,10 +1284,10 @@ uint32_t Builder::GenerateTypeConstructorExpression( bool can_cast_or_copy = result_type->is_scalar(); - if (auto* res_vec = result_type->As()) { + if (auto* res_vec = result_type->As()) { if (res_vec->type()->is_scalar()) { auto* value_type = values[0]->result_type()->UnwrapAll(); - if (auto* val_vec = value_type->As()) { + if (auto* val_vec = value_type->As()) { if (val_vec->type()->is_scalar()) { can_cast_or_copy = res_vec->size() == val_vec->size(); } @@ -1308,7 +1307,7 @@ uint32_t Builder::GenerateTypeConstructorExpression( bool result_is_constant_composite = constructor_is_const; bool result_is_spec_composite = false; - if (auto* vec = result_type->As()) { + if (auto* vec = result_type->As()) { result_type = vec->type(); } @@ -1330,9 +1329,8 @@ uint32_t Builder::GenerateTypeConstructorExpression( // If the result and value types are the same we can just use the object. // If the result is not a vector then we should have validated that the // value type is a correctly sized vector so we can just use it directly. - if (result_type == value_type || result_type->Is() || - result_type->Is() || - result_type->Is()) { + if (result_type == value_type || result_type->Is() || + result_type->Is() || result_type->Is()) { out << "_" << id; ops.push_back(Operand::Int(id)); @@ -1357,7 +1355,7 @@ uint32_t Builder::GenerateTypeConstructorExpression( // // For cases 1 and 2, if the type is different we also may need to insert // a type cast. - if (auto* vec = value_type->As()) { + if (auto* vec = value_type->As()) { auto* vec_type = vec->type(); auto value_type_id = GenerateTypeIfNeeded(vec_type); @@ -1428,7 +1426,7 @@ uint32_t Builder::GenerateTypeConstructorExpression( return result.to_i(); } -uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type, +uint32_t Builder::GenerateCastOrCopyOrPassthrough(type::Type* to_type, ast::Expression* from_expr) { auto result = result_op(); auto result_id = result.to_i(); @@ -1447,38 +1445,29 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type, auto* from_type = from_expr->result_type()->UnwrapPtrIfNeeded(); spv::Op op = spv::Op::OpNop; - if ((from_type->Is() && to_type->Is()) || + if ((from_type->Is() && to_type->Is()) || (from_type->is_signed_integer_vector() && to_type->is_float_vector())) { op = spv::Op::OpConvertSToF; - } else if ((from_type->Is() && - to_type->Is()) || + } else if ((from_type->Is() && to_type->Is()) || (from_type->is_unsigned_integer_vector() && to_type->is_float_vector())) { op = spv::Op::OpConvertUToF; - } else if ((from_type->Is() && - to_type->Is()) || + } else if ((from_type->Is() && to_type->Is()) || (from_type->is_float_vector() && to_type->is_signed_integer_vector())) { op = spv::Op::OpConvertFToS; - } else if ((from_type->Is() && - to_type->Is()) || + } else if ((from_type->Is() && to_type->Is()) || (from_type->is_float_vector() && to_type->is_unsigned_integer_vector())) { op = spv::Op::OpConvertFToU; - } else if ((from_type->Is() && - to_type->Is()) || - (from_type->Is() && - to_type->Is()) || - (from_type->Is() && - to_type->Is()) || - (from_type->Is() && - to_type->Is()) || - (from_type->Is() && (from_type == to_type))) { + } else if ((from_type->Is() && to_type->Is()) || + (from_type->Is() && to_type->Is()) || + (from_type->Is() && to_type->Is()) || + (from_type->Is() && to_type->Is()) || + (from_type->Is() && (from_type == to_type))) { return val_id; - } else if ((from_type->Is() && - to_type->Is()) || - (from_type->Is() && - to_type->Is()) || + } else if ((from_type->Is() && to_type->Is()) || + (from_type->Is() && to_type->Is()) || (from_type->is_signed_integer_vector() && to_type->is_unsigned_integer_vector()) || (from_type->is_unsigned_integer_vector() && @@ -1902,14 +1891,14 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident, params.push_back(Operand::Int(struct_id)); auto* type = accessor->structure()->result_type()->UnwrapAll(); - if (!type->Is()) { + if (!type->Is()) { error_ = "invalid type (" + type->type_name() + ") for runtime array length"; return 0; } // Runtime array must be the last member in the structure params.push_back(Operand::Int( - uint32_t(type->As()->impl()->members().size() - 1))); + uint32_t(type->As()->impl()->members().size() - 1))); if (!push_function_inst(spv::Op::OpArrayLength, params)) { return 0; @@ -2004,7 +1993,7 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, auto* texture_type = call->params()[pidx.texture] ->result_type() ->UnwrapAll() - ->As(); + ->As(); auto op = spv::Op::OpNop; @@ -2051,9 +2040,9 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, // If the texture is not a depth texture, then this function simply delegates // to calling append_result_type_and_id_to_spirv_params(). auto append_result_type_and_id_to_spirv_params_for_read = [&]() { - if (texture_type->Is()) { - auto* f32 = mod_->create(); - auto* spirv_result_type = mod_->create(f32, 4); + if (texture_type->Is()) { + auto* f32 = mod_->create(); + auto* spirv_result_type = mod_->create(f32, 4); auto spirv_result = result_op(); post_emission = [=] { return push_function_inst( @@ -2085,7 +2074,7 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, auto* element_type = ElementTypeOf(call->result_type()); auto spirv_result = result_op(); auto* spirv_result_type = - mod_->create(element_type, spirv_result_width); + mod_->create(element_type, spirv_result_width); if (swizzle.size() > 1) { post_emission = [=] { OperandList operands{ @@ -2165,26 +2154,26 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, std::vector swizzle; uint32_t spirv_dims = 0; switch (texture_type->dim()) { - case ast::type::TextureDimension::kNone: + case type::TextureDimension::kNone: error_ = "texture dimension is kNone"; return false; - case ast::type::TextureDimension::k1d: - case ast::type::TextureDimension::k2d: - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k1d: + case type::TextureDimension::k2d: + case type::TextureDimension::k3d: break; // No swizzle needed - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: swizzle = {0}; // Strip array index spirv_dims = 2; // [width, array count] break; - case ast::type::TextureDimension::kCube: + case type::TextureDimension::kCube: swizzle = {0, 1, 1}; // Duplicate height for depth spirv_dims = 2; // [width, height] break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: swizzle = {0, 1}; // Strip array index spirv_dims = 3; // [width, height, array_count] break; - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: swizzle = {0, 1, 1}; // Strip array index, duplicate height for depth spirv_dims = 3; // [width, height, array_count] break; @@ -2196,14 +2185,14 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, } spirv_params.emplace_back(gen_param(pidx.texture)); - if (texture_type->Is() || - texture_type->Is()) { + if (texture_type->Is() || + texture_type->Is()) { op = spv::Op::OpImageQuerySize; } else if (pidx.level != kNotUsed) { op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back(gen_param(pidx.level)); } else { - ast::SintLiteral i32_0(Source{}, mod_->create(), 0); + ast::SintLiteral i32_0(Source{}, mod_->create(), 0); op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back( Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); @@ -2216,11 +2205,11 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, default: error_ = "texture is not arrayed"; return false; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: spirv_dims = 2; break; - case ast::type::TextureDimension::k2dArray: - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCubeArray: spirv_dims = 3; break; } @@ -2234,11 +2223,11 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, spirv_params.emplace_back(gen_param(pidx.texture)); - if (texture_type->Is() || - texture_type->Is()) { + if (texture_type->Is() || + texture_type->Is()) { op = spv::Op::OpImageQuerySize; } else { - ast::SintLiteral i32_0(Source{}, mod_->create(), 0); + ast::SintLiteral i32_0(Source{}, mod_->create(), 0); op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back( Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); @@ -2258,9 +2247,8 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, break; } case ast::Intrinsic::kTextureLoad: { - op = texture_type->Is() - ? spv::Op::OpImageRead - : spv::Op::OpImageFetch; + op = texture_type->Is() ? spv::Op::OpImageRead + : spv::Op::OpImageFetch; append_result_type_and_id_to_spirv_params_for_read(); spirv_params.emplace_back(gen_param(pidx.texture)); if (!append_coords_to_spirv_params()) { @@ -2315,10 +2303,10 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, } assert(pidx.level != kNotUsed); auto level = Operand::Int(0); - if (call->params()[pidx.level]->result_type()->Is()) { + if (call->params()[pidx.level]->result_type()->Is()) { // Depth textures have i32 parameters for the level, but SPIR-V expects // F32. Cast. - auto* f32 = mod_->create(); + auto* f32 = mod_->create(); ast::TypeConstructorExpression cast(Source{}, f32, {call->params()[pidx.level]}); level = Operand::Int(GenerateExpression(&cast)); @@ -2354,7 +2342,7 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, assert(pidx.depth_ref != kNotUsed); spirv_params.emplace_back(gen_param(pidx.depth_ref)); - ast::type::F32 f32; + type::F32 f32; ast::FloatLiteral float_0(Source{}, &f32, 0.0); image_operands.emplace_back(ImageOperand{ SpvImageOperandsLodMask, @@ -2396,7 +2384,7 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, return post_emission(); } -uint32_t Builder::GenerateSampledImage(ast::type::Type* texture_type, +uint32_t Builder::GenerateSampledImage(type::Type* texture_type, Operand texture_operand, Operand sampler_operand) { uint32_t sampled_image_type_id = 0; @@ -2776,18 +2764,18 @@ bool Builder::GenerateVariableDeclStatement(ast::VariableDeclStatement* stmt) { return GenerateFunctionVariable(stmt->variable()); } -uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { +uint32_t Builder::GenerateTypeIfNeeded(type::Type* type) { if (type == nullptr) { error_ = "attempting to generate type from null type"; return 0; } // The alias is a wrapper around the subtype, so emit the subtype - if (auto* alias = type->As()) { + if (auto* alias = type->As()) { return GenerateTypeIfNeeded(alias->type()); } - if (auto* ac = type->As()) { - if (!ac->type()->UnwrapIfNeeded()->Is()) { + if (auto* ac = type->As()) { + if (!ac->type()->UnwrapIfNeeded()->Is()) { return GenerateTypeIfNeeded(ac->type()); } } @@ -2799,48 +2787,48 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { auto result = result_op(); auto id = result.to_i(); - if (auto* ac = type->As()) { + if (auto* ac = type->As()) { // The non-struct case was handled above. auto* subtype = ac->type()->UnwrapIfNeeded(); - if (!GenerateStructType(subtype->As(), - ac->access_control(), result)) { + if (!GenerateStructType(subtype->As(), ac->access_control(), + result)) { return 0; } - } else if (auto* arr = type->As()) { + } else if (auto* arr = type->As()) { if (!GenerateArrayType(arr, result)) { return 0; } - } else if (type->Is()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeBool, {result}); - } else if (type->Is()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeFloat, {result, Operand::Int(32)}); - } else if (type->Is()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeInt, {result, Operand::Int(32), Operand::Int(1)}); - } else if (auto* mat = type->As()) { + } else if (auto* mat = type->As()) { if (!GenerateMatrixType(mat, result)) { return 0; } - } else if (auto* ptr = type->As()) { + } else if (auto* ptr = type->As()) { if (!GeneratePointerType(ptr, result)) { return 0; } - } else if (auto* str = type->As()) { + } else if (auto* str = type->As()) { if (!GenerateStructType(str, ast::AccessControl::kReadWrite, result)) { return 0; } - } else if (type->Is()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeInt, {result, Operand::Int(32), Operand::Int(0)}); - } else if (auto* vec = type->As()) { + } else if (auto* vec = type->As()) { if (!GenerateVectorType(vec, result)) { return 0; } - } else if (type->Is()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeVoid, {result}); - } else if (auto* tex = type->As()) { + } else if (auto* tex = type->As()) { if (!GenerateTextureType(tex, result)) { return 0; } - } else if (type->Is()) { + } else if (type->Is()) { push_type(spv::Op::OpTypeSampler, {result}); // Register both of the sampler type names. In SPIR-V they're the same @@ -2858,68 +2846,68 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { } // TODO(tommek): Cover multisampled textures here when they're included in AST -bool Builder::GenerateTextureType(ast::type::Texture* texture, +bool Builder::GenerateTextureType(type::Texture* texture, const Operand& result) { uint32_t array_literal = 0u; const auto dim = texture->dim(); - if (dim == ast::type::TextureDimension::k1dArray || - dim == ast::type::TextureDimension::k2dArray || - dim == ast::type::TextureDimension::kCubeArray) { + if (dim == type::TextureDimension::k1dArray || + dim == type::TextureDimension::k2dArray || + dim == type::TextureDimension::kCubeArray) { array_literal = 1u; } uint32_t dim_literal = SpvDim2D; - if (dim == ast::type::TextureDimension::k1dArray || - dim == ast::type::TextureDimension::k1d) { + if (dim == type::TextureDimension::k1dArray || + dim == type::TextureDimension::k1d) { dim_literal = SpvDim1D; - if (texture->Is()) { + if (texture->Is()) { push_capability(SpvCapabilitySampled1D); } else { - assert(texture->Is()); + assert(texture->Is()); push_capability(SpvCapabilityImage1D); } } - if (dim == ast::type::TextureDimension::k3d) { + if (dim == type::TextureDimension::k3d) { dim_literal = SpvDim3D; } - if (dim == ast::type::TextureDimension::kCube || - dim == ast::type::TextureDimension::kCubeArray) { + if (dim == type::TextureDimension::kCube || + dim == type::TextureDimension::kCubeArray) { dim_literal = SpvDimCube; } uint32_t ms_literal = 0u; - if (texture->Is()) { + if (texture->Is()) { ms_literal = 1u; } uint32_t depth_literal = 0u; - if (texture->Is()) { + if (texture->Is()) { depth_literal = 1u; } uint32_t sampled_literal = 2u; - if (texture->Is() || - texture->Is() || - texture->Is()) { + if (texture->Is() || + texture->Is() || + texture->Is()) { sampled_literal = 1u; } - if (dim == ast::type::TextureDimension::kCubeArray) { - if (texture->Is() || - texture->Is()) { + if (dim == type::TextureDimension::kCubeArray) { + if (texture->Is() || + texture->Is()) { push_capability(SpvCapabilitySampledCubeArray); } } uint32_t type_id = 0u; - if (texture->Is()) { - ast::type::F32 f32; + if (texture->Is()) { + type::F32 f32; type_id = GenerateTypeIfNeeded(&f32); - } else if (auto* s = texture->As()) { + } else if (auto* s = texture->As()) { type_id = GenerateTypeIfNeeded(s->type()); - } else if (auto* ms = texture->As()) { + } else if (auto* ms = texture->As()) { type_id = GenerateTypeIfNeeded(ms->type()); - } else if (auto* st = texture->As()) { + } else if (auto* st = texture->As()) { type_id = GenerateTypeIfNeeded(st->type()); } if (type_id == 0u) { @@ -2927,7 +2915,7 @@ bool Builder::GenerateTextureType(ast::type::Texture* texture, } uint32_t format_literal = SpvImageFormat_::SpvImageFormatUnknown; - if (auto* t = texture->As()) { + if (auto* t = texture->As()) { format_literal = convert_image_format_to_spv(t->image_format()); } @@ -2940,7 +2928,7 @@ bool Builder::GenerateTextureType(ast::type::Texture* texture, return true; } -bool Builder::GenerateArrayType(ast::type::Array* ary, const Operand& result) { +bool Builder::GenerateArrayType(type::Array* ary, const Operand& result) { auto elem_type = GenerateTypeIfNeeded(ary->type()); if (elem_type == 0) { return false; @@ -2967,9 +2955,8 @@ bool Builder::GenerateArrayType(ast::type::Array* ary, const Operand& result) { return true; } -bool Builder::GenerateMatrixType(ast::type::Matrix* mat, - const Operand& result) { - ast::type::Vector col_type(mat->type(), mat->rows()); +bool Builder::GenerateMatrixType(type::Matrix* mat, const Operand& result) { + type::Vector col_type(mat->type(), mat->rows()); auto col_type_id = GenerateTypeIfNeeded(&col_type); if (has_error()) { return false; @@ -2980,8 +2967,7 @@ bool Builder::GenerateMatrixType(ast::type::Matrix* mat, return true; } -bool Builder::GeneratePointerType(ast::type::Pointer* ptr, - const Operand& result) { +bool Builder::GeneratePointerType(type::Pointer* ptr, const Operand& result) { auto pointee_id = GenerateTypeIfNeeded(ptr->type()); if (pointee_id == 0) { return false; @@ -2999,7 +2985,7 @@ bool Builder::GeneratePointerType(ast::type::Pointer* ptr, return true; } -bool Builder::GenerateStructType(ast::type::Struct* struct_type, +bool Builder::GenerateStructType(type::Struct* struct_type, ast::AccessControl access_control, const Operand& result) { auto struct_id = result.to_i(); @@ -3074,7 +3060,7 @@ uint32_t Builder::GenerateStructMember(uint32_t struct_id, push_annot(spv::Op::OpMemberDecorate, {Operand::Int(struct_id), Operand::Int(idx), Operand::Int(SpvDecorationColMajor)}); - if (!matrix_type->type()->Is()) { + if (!matrix_type->type()->Is()) { error_ = "matrix scalar element type must be f32"; return 0; } @@ -3090,8 +3076,7 @@ uint32_t Builder::GenerateStructMember(uint32_t struct_id, return GenerateTypeIfNeeded(member->type()); } -bool Builder::GenerateVectorType(ast::type::Vector* vec, - const Operand& result) { +bool Builder::GenerateVectorType(type::Vector* vec, const Operand& result) { auto type_id = GenerateTypeIfNeeded(vec->type()); if (has_error()) { return false; @@ -3157,98 +3142,98 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::Builtin builtin) const { } SpvImageFormat Builder::convert_image_format_to_spv( - const ast::type::ImageFormat format) { + const type::ImageFormat format) { switch (format) { - case ast::type::ImageFormat::kR8Unorm: + case type::ImageFormat::kR8Unorm: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR8; - case ast::type::ImageFormat::kR8Snorm: + case type::ImageFormat::kR8Snorm: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR8Snorm; - case ast::type::ImageFormat::kR8Uint: + case type::ImageFormat::kR8Uint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR8ui; - case ast::type::ImageFormat::kR8Sint: + case type::ImageFormat::kR8Sint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR8i; - case ast::type::ImageFormat::kR16Uint: + case type::ImageFormat::kR16Uint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR16ui; - case ast::type::ImageFormat::kR16Sint: + case type::ImageFormat::kR16Sint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR16i; - case ast::type::ImageFormat::kR16Float: + case type::ImageFormat::kR16Float: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR16f; - case ast::type::ImageFormat::kRg8Unorm: + case type::ImageFormat::kRg8Unorm: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg8; - case ast::type::ImageFormat::kRg8Snorm: + case type::ImageFormat::kRg8Snorm: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg8Snorm; - case ast::type::ImageFormat::kRg8Uint: + case type::ImageFormat::kRg8Uint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg8ui; - case ast::type::ImageFormat::kRg8Sint: + case type::ImageFormat::kRg8Sint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg8i; - case ast::type::ImageFormat::kR32Uint: + case type::ImageFormat::kR32Uint: return SpvImageFormatR32ui; - case ast::type::ImageFormat::kR32Sint: + case type::ImageFormat::kR32Sint: return SpvImageFormatR32i; - case ast::type::ImageFormat::kR32Float: + case type::ImageFormat::kR32Float: return SpvImageFormatR32f; - case ast::type::ImageFormat::kRg16Uint: + case type::ImageFormat::kRg16Uint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg16ui; - case ast::type::ImageFormat::kRg16Sint: + case type::ImageFormat::kRg16Sint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg16i; - case ast::type::ImageFormat::kRg16Float: + case type::ImageFormat::kRg16Float: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg16f; - case ast::type::ImageFormat::kRgba8Unorm: + case type::ImageFormat::kRgba8Unorm: return SpvImageFormatRgba8; - case ast::type::ImageFormat::kRgba8UnormSrgb: + case type::ImageFormat::kRgba8UnormSrgb: return SpvImageFormatUnknown; - case ast::type::ImageFormat::kRgba8Snorm: + case type::ImageFormat::kRgba8Snorm: return SpvImageFormatRgba8Snorm; - case ast::type::ImageFormat::kRgba8Uint: + case type::ImageFormat::kRgba8Uint: return SpvImageFormatRgba8ui; - case ast::type::ImageFormat::kRgba8Sint: + case type::ImageFormat::kRgba8Sint: return SpvImageFormatRgba8i; - case ast::type::ImageFormat::kBgra8Unorm: + case type::ImageFormat::kBgra8Unorm: return SpvImageFormatUnknown; - case ast::type::ImageFormat::kBgra8UnormSrgb: + case type::ImageFormat::kBgra8UnormSrgb: return SpvImageFormatUnknown; - case ast::type::ImageFormat::kRgb10A2Unorm: + case type::ImageFormat::kRgb10A2Unorm: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRgb10A2; - case ast::type::ImageFormat::kRg11B10Float: + case type::ImageFormat::kRg11B10Float: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatR11fG11fB10f; - case ast::type::ImageFormat::kRg32Uint: + case type::ImageFormat::kRg32Uint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg32ui; - case ast::type::ImageFormat::kRg32Sint: + case type::ImageFormat::kRg32Sint: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg32i; - case ast::type::ImageFormat::kRg32Float: + case type::ImageFormat::kRg32Float: push_capability(SpvCapabilityStorageImageExtendedFormats); return SpvImageFormatRg32f; - case ast::type::ImageFormat::kRgba16Uint: + case type::ImageFormat::kRgba16Uint: return SpvImageFormatRgba16ui; - case ast::type::ImageFormat::kRgba16Sint: + case type::ImageFormat::kRgba16Sint: return SpvImageFormatRgba16i; - case ast::type::ImageFormat::kRgba16Float: + case type::ImageFormat::kRgba16Float: return SpvImageFormatRgba16f; - case ast::type::ImageFormat::kRgba32Uint: + case type::ImageFormat::kRgba32Uint: return SpvImageFormatRgba32ui; - case ast::type::ImageFormat::kRgba32Sint: + case type::ImageFormat::kRgba32Sint: return SpvImageFormatRgba32i; - case ast::type::ImageFormat::kRgba32Float: + case type::ImageFormat::kRgba32Float: return SpvImageFormatRgba32f; - case ast::type::ImageFormat::kNone: + case type::ImageFormat::kNone: return SpvImageFormatUnknown; } return SpvImageFormatUnknown; diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index 6e0c4465ce..9a76a0dbc3 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -41,17 +41,17 @@ #include "src/ast/return_statement.h" #include "src/ast/struct_member.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable_decl_statement.h" #include "src/scope_stack.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/matrix_type.h" +#include "src/type/pointer_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" #include "src/writer/spirv/function.h" #include "src/writer/spirv/instruction.h" @@ -75,7 +75,7 @@ class Builder { uint32_t source_id; /// The type of the current chain source. This type matches the deduced /// result_type of the current source defined above. - ast::type::Type* source_type; + type::Type* source_type; /// A list of access chain indices to emit. Note, we _only_ have access /// chain indices if the source is pointer. std::vector access_chain_indices; @@ -269,7 +269,7 @@ class Builder { /// @param type the type to generate for /// @param struct_id the struct id /// @param member_idx the member index - void GenerateMemberAccessControlIfNeeded(ast::type::Type* type, + void GenerateMemberAccessControlIfNeeded(type::Type* type, uint32_t struct_id, uint32_t member_idx); /// Generates a function variable @@ -373,7 +373,7 @@ class Builder { /// @param texture_operand the texture operand /// @param sampler_operand the sampler operand /// @returns the expression ID - uint32_t GenerateSampledImage(ast::type::Type* texture_type, + uint32_t GenerateSampledImage(type::Type* texture_type, Operand texture_operand, Operand sampler_operand); /// Generates a cast or object copy for the expression result, @@ -382,7 +382,7 @@ class Builder { /// @param to_type the type we're casting too /// @param from_expr the expression to cast /// @returns the expression ID on success or 0 otherwise - uint32_t GenerateCastOrCopyOrPassthrough(ast::type::Type* to_type, + uint32_t GenerateCastOrCopyOrPassthrough(type::Type* to_type, ast::Expression* from_expr); /// Generates a loop statement /// @param stmt the statement to generate @@ -414,7 +414,7 @@ class Builder { /// @param type the type to load /// @param id the variable id to load /// @returns the ID of the loaded value or `id` if type is not a pointer - uint32_t GenerateLoadIfNeeded(ast::type::Type* type, uint32_t id); + uint32_t GenerateLoadIfNeeded(type::Type* type, uint32_t id); /// Generates an OpStore. Emits an error and returns false if we're /// currently outside a function. /// @param to the ID to store too @@ -424,33 +424,33 @@ class Builder { /// Generates a type if not already created /// @param type the type to create /// @returns the ID to use for the given type. Returns 0 on unknown type. - uint32_t GenerateTypeIfNeeded(ast::type::Type* type); + uint32_t GenerateTypeIfNeeded(type::Type* type); /// Generates a texture type declaration /// @param texture the texture to generate /// @param result the result operand /// @returns true if the texture was successfully generated - bool GenerateTextureType(ast::type::Texture* texture, const Operand& result); + bool GenerateTextureType(type::Texture* texture, const Operand& result); /// Generates an array type declaration /// @param ary the array to generate /// @param result the result operand /// @returns true if the array was successfully generated - bool GenerateArrayType(ast::type::Array* ary, const Operand& result); + bool GenerateArrayType(type::Array* ary, const Operand& result); /// Generates a matrix type declaration /// @param mat the matrix to generate /// @param result the result operand /// @returns true if the matrix was successfully generated - bool GenerateMatrixType(ast::type::Matrix* mat, const Operand& result); + bool GenerateMatrixType(type::Matrix* mat, const Operand& result); /// Generates a pointer type declaration /// @param ptr the pointer type to generate /// @param result the result operand /// @returns true if the pointer was successfully generated - bool GeneratePointerType(ast::type::Pointer* ptr, const Operand& result); + bool GeneratePointerType(type::Pointer* ptr, const Operand& result); /// Generates a vector type declaration /// @param struct_type the vector to generate /// @param access_control the access controls to assign to the struct /// @param result the result operand /// @returns true if the vector was successfully generated - bool GenerateStructType(ast::type::Struct* struct_type, + bool GenerateStructType(type::Struct* struct_type, ast::AccessControl access_control, const Operand& result); /// Generates a struct member @@ -469,13 +469,12 @@ class Builder { /// @param vec the vector to generate /// @param result the result operand /// @returns true if the vector was successfully generated - bool GenerateVectorType(ast::type::Vector* vec, const Operand& result); + bool GenerateVectorType(type::Vector* vec, const Operand& result); /// Converts AST image format to SPIR-V and pushes an appropriate capability. /// @param format AST image format type /// @returns SPIR-V image format type - SpvImageFormat convert_image_format_to_spv( - const ast::type::ImageFormat format); + SpvImageFormat convert_image_format_to_spv(const type::ImageFormat format); /// Determines if the given type constructor is created from constant values /// @param expr the expression to check diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index 6fdd1c6d3b..8159bfff83 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -24,15 +24,15 @@ #include "src/ast/sint_literal.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" +#include "src/type/array_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" @@ -159,7 +159,7 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) { } TEST_F(BuilderTest, ArrayAccessor_MultiLevel) { - ast::type::Array ary4(ty.vec3(), 4, ast::ArrayDecorationList{}); + type::Array ary4(ty.vec3(), 4, ast::ArrayDecorationList{}); // ary = array, 4> // ary[3][2]; @@ -197,7 +197,7 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) { } TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) { - ast::type::Array ary4(ty.vec3(), 4, ast::ArrayDecorationList{}); + type::Array ary4(ty.vec3(), 4, ast::ArrayDecorationList{}); // var a : array, 4>; // a[2].xy; @@ -658,12 +658,12 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) { s = create(ast::StructMemberList{Member("bar", c_type)}, ast::StructDecorationList{}); auto* b_type = ty.struct_("B", s); - ast::type::Array b_ary_type(b_type, 3, ast::ArrayDecorationList{}); + type::Array b_ary_type(b_type, 3, ast::ArrayDecorationList{}); s = create(ast::StructMemberList{Member("foo", &b_ary_type)}, ast::StructDecorationList{}); auto* a_type = ty.struct_("A", s); - ast::type::Array a_ary_type(a_type, 2, ast::ArrayDecorationList{}); + type::Array a_ary_type(a_type, 2, ast::ArrayDecorationList{}); auto* var = Var("index", ast::StorageClass::kFunction, &a_ary_type); auto* expr = MemberAccessor( MemberAccessor( @@ -718,7 +718,7 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) { // vec2(0.5, -0.5)); // pos[1] - ast::type::Array arr(ty.vec2(), 3, ast::ArrayDecorationList{}); + type::Array arr(ty.vec2(), 3, ast::ArrayDecorationList{}); auto* var = Const("pos", ast::StorageClass::kPrivate, &arr, Construct(&arr, vec2(0.0f, 0.5f), diff --git a/src/writer/spirv/builder_assign_test.cc b/src/writer/spirv/builder_assign_test.cc index 463dbf7368..040cac9aad 100644 --- a/src/writer/spirv/builder_assign_test.cc +++ b/src/writer/spirv/builder_assign_test.cc @@ -24,11 +24,11 @@ #include "src/ast/sint_literal.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc index e614b5137b..8f2b5a8302 100644 --- a/src/writer/spirv/builder_binary_expression_test.cc +++ b/src/writer/spirv/builder_binary_expression_test.cc @@ -21,14 +21,14 @@ #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_bitcast_expression_test.cc b/src/writer/spirv/builder_bitcast_expression_test.cc index e64aecf80e..2b0ba00e96 100644 --- a/src/writer/spirv/builder_bitcast_expression_test.cc +++ b/src/writer/spirv/builder_bitcast_expression_test.cc @@ -17,8 +17,8 @@ #include "src/ast/float_literal.h" #include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/u32_type.h" +#include "src/type/f32_type.h" +#include "src/type/u32_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_block_test.cc b/src/writer/spirv/builder_block_test.cc index 70a08d05a0..e751849e70 100644 --- a/src/writer/spirv/builder_block_test.cc +++ b/src/writer/spirv/builder_block_test.cc @@ -20,8 +20,8 @@ #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/f32_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_call_test.cc b/src/writer/spirv/builder_call_test.cc index 51d9e9f814..e1cf83f0ce 100644 --- a/src/writer/spirv/builder_call_test.cc +++ b/src/writer/spirv/builder_call_test.cc @@ -24,9 +24,9 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_constructor_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc index 0b8c9e1dff..a4f675a30a 100644 --- a/src/writer/spirv/builder_constructor_expression_test.cc +++ b/src/writer/spirv/builder_constructor_expression_test.cc @@ -27,16 +27,16 @@ #include "src/ast/struct.h" #include "src/ast/struct_decoration.h" #include "src/ast/struct_member.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_format_conversion_test.cc b/src/writer/spirv/builder_format_conversion_test.cc index 4de15f4f7f..0c9df47213 100644 --- a/src/writer/spirv/builder_format_conversion_test.cc +++ b/src/writer/spirv/builder_format_conversion_test.cc @@ -23,7 +23,7 @@ namespace spirv { namespace { struct TestData { - ast::type::ImageFormat ast_format; + type::ImageFormat ast_format; SpvImageFormat_ spv_format; bool extended_format = false; }; @@ -51,46 +51,42 @@ INSTANTIATE_TEST_SUITE_P( BuilderTest, ImageFormatConversionTest, testing::Values( - TestData{ast::type::ImageFormat::kR8Unorm, SpvImageFormatR8, true}, - TestData{ast::type::ImageFormat::kR8Snorm, SpvImageFormatR8Snorm, true}, - TestData{ast::type::ImageFormat::kR8Uint, SpvImageFormatR8ui, true}, - TestData{ast::type::ImageFormat::kR8Sint, SpvImageFormatR8i, true}, - TestData{ast::type::ImageFormat::kR16Uint, SpvImageFormatR16ui, true}, - TestData{ast::type::ImageFormat::kR16Sint, SpvImageFormatR16i, true}, - TestData{ast::type::ImageFormat::kR16Float, SpvImageFormatR16f, true}, - TestData{ast::type::ImageFormat::kRg8Unorm, SpvImageFormatRg8, true}, - TestData{ast::type::ImageFormat::kRg8Snorm, SpvImageFormatRg8Snorm, + TestData{type::ImageFormat::kR8Unorm, SpvImageFormatR8, true}, + TestData{type::ImageFormat::kR8Snorm, SpvImageFormatR8Snorm, true}, + TestData{type::ImageFormat::kR8Uint, SpvImageFormatR8ui, true}, + TestData{type::ImageFormat::kR8Sint, SpvImageFormatR8i, true}, + TestData{type::ImageFormat::kR16Uint, SpvImageFormatR16ui, true}, + TestData{type::ImageFormat::kR16Sint, SpvImageFormatR16i, true}, + TestData{type::ImageFormat::kR16Float, SpvImageFormatR16f, true}, + TestData{type::ImageFormat::kRg8Unorm, SpvImageFormatRg8, true}, + TestData{type::ImageFormat::kRg8Snorm, SpvImageFormatRg8Snorm, true}, + TestData{type::ImageFormat::kRg8Uint, SpvImageFormatRg8ui, true}, + TestData{type::ImageFormat::kRg8Sint, SpvImageFormatRg8i, true}, + TestData{type::ImageFormat::kR32Uint, SpvImageFormatR32ui}, + TestData{type::ImageFormat::kR32Sint, SpvImageFormatR32i}, + TestData{type::ImageFormat::kR32Float, SpvImageFormatR32f}, + TestData{type::ImageFormat::kRg16Uint, SpvImageFormatRg16ui, true}, + TestData{type::ImageFormat::kRg16Sint, SpvImageFormatRg16i, true}, + TestData{type::ImageFormat::kRg16Float, SpvImageFormatRg16f, true}, + TestData{type::ImageFormat::kRgba8Unorm, SpvImageFormatRgba8}, + TestData{type::ImageFormat::kRgba8UnormSrgb, SpvImageFormatUnknown}, + TestData{type::ImageFormat::kRgba8Snorm, SpvImageFormatRgba8Snorm}, + TestData{type::ImageFormat::kRgba8Uint, SpvImageFormatRgba8ui}, + TestData{type::ImageFormat::kRgba8Sint, SpvImageFormatRgba8i}, + TestData{type::ImageFormat::kBgra8Unorm, SpvImageFormatUnknown}, + TestData{type::ImageFormat::kBgra8UnormSrgb, SpvImageFormatUnknown}, + TestData{type::ImageFormat::kRgb10A2Unorm, SpvImageFormatRgb10A2, true}, + TestData{type::ImageFormat::kRg11B10Float, SpvImageFormatR11fG11fB10f, true}, - TestData{ast::type::ImageFormat::kRg8Uint, SpvImageFormatRg8ui, true}, - TestData{ast::type::ImageFormat::kRg8Sint, SpvImageFormatRg8i, true}, - TestData{ast::type::ImageFormat::kR32Uint, SpvImageFormatR32ui}, - TestData{ast::type::ImageFormat::kR32Sint, SpvImageFormatR32i}, - TestData{ast::type::ImageFormat::kR32Float, SpvImageFormatR32f}, - TestData{ast::type::ImageFormat::kRg16Uint, SpvImageFormatRg16ui, true}, - TestData{ast::type::ImageFormat::kRg16Sint, SpvImageFormatRg16i, true}, - TestData{ast::type::ImageFormat::kRg16Float, SpvImageFormatRg16f, true}, - TestData{ast::type::ImageFormat::kRgba8Unorm, SpvImageFormatRgba8}, - TestData{ast::type::ImageFormat::kRgba8UnormSrgb, - SpvImageFormatUnknown}, - TestData{ast::type::ImageFormat::kRgba8Snorm, SpvImageFormatRgba8Snorm}, - TestData{ast::type::ImageFormat::kRgba8Uint, SpvImageFormatRgba8ui}, - TestData{ast::type::ImageFormat::kRgba8Sint, SpvImageFormatRgba8i}, - TestData{ast::type::ImageFormat::kBgra8Unorm, SpvImageFormatUnknown}, - TestData{ast::type::ImageFormat::kBgra8UnormSrgb, - SpvImageFormatUnknown}, - TestData{ast::type::ImageFormat::kRgb10A2Unorm, SpvImageFormatRgb10A2, - true}, - TestData{ast::type::ImageFormat::kRg11B10Float, - SpvImageFormatR11fG11fB10f, true}, - TestData{ast::type::ImageFormat::kRg32Uint, SpvImageFormatRg32ui, true}, - TestData{ast::type::ImageFormat::kRg32Sint, SpvImageFormatRg32i, true}, - TestData{ast::type::ImageFormat::kRg32Float, SpvImageFormatRg32f, true}, - TestData{ast::type::ImageFormat::kRgba16Uint, SpvImageFormatRgba16ui}, - TestData{ast::type::ImageFormat::kRgba16Sint, SpvImageFormatRgba16i}, - TestData{ast::type::ImageFormat::kRgba16Float, SpvImageFormatRgba16f}, - TestData{ast::type::ImageFormat::kRgba32Uint, SpvImageFormatRgba32ui}, - TestData{ast::type::ImageFormat::kRgba32Sint, SpvImageFormatRgba32i}, - TestData{ast::type::ImageFormat::kRgba32Float, SpvImageFormatRgba32f})); + TestData{type::ImageFormat::kRg32Uint, SpvImageFormatRg32ui, true}, + TestData{type::ImageFormat::kRg32Sint, SpvImageFormatRg32i, true}, + TestData{type::ImageFormat::kRg32Float, SpvImageFormatRg32f, true}, + TestData{type::ImageFormat::kRgba16Uint, SpvImageFormatRgba16ui}, + TestData{type::ImageFormat::kRgba16Sint, SpvImageFormatRgba16i}, + TestData{type::ImageFormat::kRgba16Float, SpvImageFormatRgba16f}, + TestData{type::ImageFormat::kRgba32Uint, SpvImageFormatRgba32ui}, + TestData{type::ImageFormat::kRgba32Sint, SpvImageFormatRgba32i}, + TestData{type::ImageFormat::kRgba32Float, SpvImageFormatRgba32f})); } // namespace } // namespace spirv diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index 3c4c00d5ad..cc04b1ccf1 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -26,13 +26,13 @@ #include "src/ast/struct.h" #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/access_control_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" @@ -217,7 +217,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { ast::StructMemberList{Member("d", ty.f32, {MemberOffset(0)})}, s_decos); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ diff --git a/src/writer/spirv/builder_function_variable_test.cc b/src/writer/spirv/builder_function_variable_test.cc index a113faaeb3..21bccc5f9d 100644 --- a/src/writer/spirv/builder_function_variable_test.cc +++ b/src/writer/spirv/builder_function_variable_test.cc @@ -25,10 +25,10 @@ #include "src/ast/scalar_constructor_expression.h" #include "src/ast/storage_class.h" #include "src/ast/struct.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/access_control_type.h" +#include "src/type/f32_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 0a1cc4db34..cb0184cc40 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -27,16 +27,16 @@ #include "src/ast/scalar_constructor_expression.h" #include "src/ast/storage_class.h" #include "src/ast/struct.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" +#include "src/type/access_control_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" @@ -384,7 +384,7 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) { "A", create( ast::StructMemberList{Member("a", ty.i32), Member("b", ty.i32)}, ast::StructDecorationList{})); - ast::type::AccessControl ac{ast::AccessControl::kReadOnly, A}; + type::AccessControl ac{ast::AccessControl::kReadOnly, A}; auto* var = Var("b", ast::StorageClass::kStorage, &ac); EXPECT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -415,7 +415,7 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) { "A", create(ast::StructMemberList{Member("a", ty.i32)}, ast::StructDecorationList{})); auto* B = ty.alias("B", A); - ast::type::AccessControl ac{ast::AccessControl::kReadOnly, B}; + type::AccessControl ac{ast::AccessControl::kReadOnly, B}; auto* var = Var("b", ast::StorageClass::kStorage, &ac); EXPECT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -442,7 +442,7 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) { auto* A = ty.struct_( "A", create(ast::StructMemberList{Member("a", ty.i32)}, ast::StructDecorationList{})); - ast::type::AccessControl ac{ast::AccessControl::kReadOnly, A}; + type::AccessControl ac{ast::AccessControl::kReadOnly, A}; auto* B = ty.alias("B", &ac); auto* var = Var("b", ast::StorageClass::kStorage, B); EXPECT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -470,8 +470,8 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) { auto* A = ty.struct_( "A", create(ast::StructMemberList{Member("a", ty.i32)}, ast::StructDecorationList{})); - ast::type::AccessControl read{ast::AccessControl::kReadOnly, A}; - ast::type::AccessControl rw{ast::AccessControl::kReadWrite, A}; + type::AccessControl read{ast::AccessControl::kReadOnly, A}; + type::AccessControl rw{ast::AccessControl::kReadWrite, A}; auto* var_b = Var("b", ast::StorageClass::kStorage, &read); auto* var_c = Var("c", ast::StorageClass::kStorage, &rw); @@ -500,11 +500,11 @@ OpName %5 "c" TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) { // var a : [[access(read)]] texture_storage_2d; - ast::type::StorageTexture type(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR32Uint); + type::StorageTexture type(type::TextureDimension::k2d, + type::ImageFormat::kR32Uint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&type)) << td.error(); - ast::type::AccessControl ac(ast::AccessControl::kReadOnly, &type); + type::AccessControl ac(ast::AccessControl::kReadOnly, &type); auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &ac); EXPECT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); @@ -521,11 +521,11 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) { TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { // var a : [[access(write)]] texture_storage_2d; - ast::type::StorageTexture type(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR32Uint); + type::StorageTexture type(type::TextureDimension::k2d, + type::ImageFormat::kR32Uint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&type)) << td.error(); - ast::type::AccessControl ac(ast::AccessControl::kWriteOnly, &type); + type::AccessControl ac(ast::AccessControl::kWriteOnly, &type); auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &ac); EXPECT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); @@ -545,15 +545,15 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWithDifferentAccess) { // var a : [[access(read)]] texture_storage_2d; // var b : [[access(write)]] texture_storage_2d; - ast::type::StorageTexture st(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR32Uint); + type::StorageTexture st(type::TextureDimension::k2d, + type::ImageFormat::kR32Uint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&st)) << td.error(); - ast::type::AccessControl type_a(ast::AccessControl::kReadOnly, &st); + type::AccessControl type_a(ast::AccessControl::kReadOnly, &st); auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &type_a); EXPECT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); - ast::type::AccessControl type_b(ast::AccessControl::kWriteOnly, &st); + type::AccessControl type_b(ast::AccessControl::kWriteOnly, &st); auto* var_b = Var("b", ast::StorageClass::kUniformConstant, &type_b); EXPECT_TRUE(b.GenerateGlobalVariable(var_b)) << b.error(); diff --git a/src/writer/spirv/builder_ident_expression_test.cc b/src/writer/spirv/builder_ident_expression_test.cc index 453ef6bcae..083abb7796 100644 --- a/src/writer/spirv/builder_ident_expression_test.cc +++ b/src/writer/spirv/builder_ident_expression_test.cc @@ -20,11 +20,11 @@ #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_if_test.cc b/src/writer/spirv/builder_if_test.cc index 25e03b89a2..f826e0ab23 100644 --- a/src/writer/spirv/builder_if_test.cc +++ b/src/writer/spirv/builder_if_test.cc @@ -26,8 +26,8 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/i32_type.h" +#include "src/type/bool_type.h" +#include "src/type/i32_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index 654317b2a6..d1d7a8d6d3 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -25,23 +25,23 @@ #include "src/ast/sint_literal.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" @@ -383,8 +383,8 @@ TEST_F(IntrinsicBuilderTest, Call_Select) { // This tests that we do not push OpTypeSampledImage and float_0 type twice. TEST_F(IntrinsicBuilderTest, Call_TextureSampleCompare_Twice) { - ast::type::Sampler s(ast::type::SamplerKind::kComparisonSampler); - ast::type::DepthTexture t(ast::type::TextureDimension::k2d); + type::Sampler s(type::SamplerKind::kComparisonSampler); + type::DepthTexture t(type::TextureDimension::k2d); b.push_function(Function{}); diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc index 9c1e2513a1..33f2259728 100644 --- a/src/writer/spirv/builder_intrinsic_texture_test.cc +++ b/src/writer/spirv/builder_intrinsic_texture_test.cc @@ -20,10 +20,10 @@ #include "src/ast/call_statement.h" #include "src/ast/intrinsic_texture_helper_test.h" #include "src/ast/stage_decoration.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/binary_writer.h" #include "src/writer/spirv/builder.h" diff --git a/src/writer/spirv/builder_literal_test.cc b/src/writer/spirv/builder_literal_test.cc index b641b92ba2..59d0757ebd 100644 --- a/src/writer/spirv/builder_literal_test.cc +++ b/src/writer/spirv/builder_literal_test.cc @@ -18,11 +18,11 @@ #include "src/ast/float_literal.h" #include "src/ast/literal.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/u32_type.h" #include "src/ast/uint_literal.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/u32_type.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" #include "src/writer/spirv/test_helper.h" diff --git a/src/writer/spirv/builder_loop_test.cc b/src/writer/spirv/builder_loop_test.cc index b9cfb02559..fc1141ae72 100644 --- a/src/writer/spirv/builder_loop_test.cc +++ b/src/writer/spirv/builder_loop_test.cc @@ -22,7 +22,7 @@ #include "src/ast/loop_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_return_test.cc b/src/writer/spirv/builder_return_test.cc index d3a55ff039..017ac29e40 100644 --- a/src/writer/spirv/builder_return_test.cc +++ b/src/writer/spirv/builder_return_test.cc @@ -19,9 +19,9 @@ #include "src/ast/identifier_expression.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" +#include "src/type/vector_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_switch_test.cc b/src/writer/spirv/builder_switch_test.cc index 71505292d3..d320474280 100644 --- a/src/writer/spirv/builder_switch_test.cc +++ b/src/writer/spirv/builder_switch_test.cc @@ -25,8 +25,8 @@ #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/i32_type.h" +#include "src/type/bool_type.h" +#include "src/type/i32_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index b1cf1c0825..756e8851ae 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -21,24 +21,24 @@ #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/alias_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/texture_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/access_control_type.h" +#include "src/type/alias_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/texture_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" #include "src/writer/spirv/spv_dump.h" @@ -76,7 +76,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedAlias) { } TEST_F(BuilderTest_Type, GenerateRuntimeArray) { - ast::type::Array ary(ty.i32, 0, ast::ArrayDecorationList{}); + type::Array ary(ty.i32, 0, ast::ArrayDecorationList{}); auto id = b.GenerateTypeIfNeeded(&ary); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(1u, id); @@ -87,7 +87,7 @@ TEST_F(BuilderTest_Type, GenerateRuntimeArray) { } TEST_F(BuilderTest_Type, ReturnsGeneratedRuntimeArray) { - ast::type::Array ary(ty.i32, 0, ast::ArrayDecorationList{}); + type::Array ary(ty.i32, 0, ast::ArrayDecorationList{}); EXPECT_EQ(b.GenerateTypeIfNeeded(&ary), 1u); EXPECT_EQ(b.GenerateTypeIfNeeded(&ary), 1u); @@ -99,7 +99,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedRuntimeArray) { } TEST_F(BuilderTest_Type, GenerateArray) { - ast::type::Array ary(ty.i32, 4, ast::ArrayDecorationList{}); + type::Array ary(ty.i32, 4, ast::ArrayDecorationList{}); auto id = b.GenerateTypeIfNeeded(&ary); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(1u, id); @@ -112,10 +112,10 @@ TEST_F(BuilderTest_Type, GenerateArray) { } TEST_F(BuilderTest_Type, GenerateArray_WithStride) { - ast::type::Array ary(ty.i32, 4, - ast::ArrayDecorationList{ - create(16u), - }); + type::Array ary(ty.i32, 4, + ast::ArrayDecorationList{ + create(16u), + }); auto id = b.GenerateTypeIfNeeded(&ary); ASSERT_FALSE(b.has_error()) << b.error(); @@ -132,7 +132,7 @@ TEST_F(BuilderTest_Type, GenerateArray_WithStride) { } TEST_F(BuilderTest_Type, ReturnsGeneratedArray) { - ast::type::Array ary(ty.i32, 4, ast::ArrayDecorationList{}); + type::Array ary(ty.i32, 4, ast::ArrayDecorationList{}); EXPECT_EQ(b.GenerateTypeIfNeeded(&ary), 1u); EXPECT_EQ(b.GenerateTypeIfNeeded(&ary), 1u); @@ -225,7 +225,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedMatrix) { } TEST_F(BuilderTest_Type, GeneratePtr) { - ast::type::Pointer ptr(ty.i32, ast::StorageClass::kOutput); + type::Pointer ptr(ty.i32, ast::StorageClass::kOutput); auto id = b.GenerateTypeIfNeeded(&ptr); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(1u, id); @@ -236,7 +236,7 @@ TEST_F(BuilderTest_Type, GeneratePtr) { } TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) { - ast::type::Pointer ptr(ty.i32, ast::StorageClass::kOutput); + type::Pointer ptr(ty.i32, ast::StorageClass::kOutput); EXPECT_EQ(b.GenerateTypeIfNeeded(&ptr), 1u); EXPECT_EQ(b.GenerateTypeIfNeeded(&ptr), 1u); } @@ -391,15 +391,15 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) { // We have to infer layout for matrix when it also has an offset. // The decoration goes on the struct member, even if the matrix is buried // in levels of arrays. - ast::type::Array arr_mat2x2( - ty.mat2x2(), 1, ast::ArrayDecorationList{}); // Singly nested array + type::Array arr_mat2x2(ty.mat2x2(), 1, + ast::ArrayDecorationList{}); // Singly nested array - ast::type::Array arr_mat2x3(ty.mat2x3(), 1, ast::ArrayDecorationList{}); - ast::type::Array arr_arr_mat2x3( + type::Array arr_mat2x3(ty.mat2x3(), 1, ast::ArrayDecorationList{}); + type::Array arr_arr_mat2x3( ty.mat2x3(), 1, ast::ArrayDecorationList{}); // Doubly nested array - ast::type::Array rtarr_mat4x4(ty.mat4x4(), 0, - ast::ArrayDecorationList{}); // Runtime array + type::Array rtarr_mat4x4(ty.mat4x4(), 0, + ast::ArrayDecorationList{}); // Runtime array auto* s = create( ast::StructMemberList{Member("a", &arr_mat2x2, {MemberOffset(0)}), @@ -533,7 +533,7 @@ INSTANTIATE_TEST_SUITE_P( PtrData{ast::StorageClass::kFunction, SpvStorageClassFunction})); TEST_F(BuilderTest_Type, DepthTexture_Generate_2d) { - ast::type::DepthTexture two_d(ast::type::TextureDimension::k2d); + type::DepthTexture two_d(type::TextureDimension::k2d); auto id_two_d = b.GenerateTypeIfNeeded(&two_d); ASSERT_FALSE(b.has_error()) << b.error(); @@ -545,7 +545,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_2d) { } TEST_F(BuilderTest_Type, DepthTexture_Generate_2dArray) { - ast::type::DepthTexture two_d_array(ast::type::TextureDimension::k2dArray); + type::DepthTexture two_d_array(type::TextureDimension::k2dArray); auto id_two_d_array = b.GenerateTypeIfNeeded(&two_d_array); ASSERT_FALSE(b.has_error()) << b.error(); @@ -557,7 +557,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, DepthTexture_Generate_Cube) { - ast::type::DepthTexture cube(ast::type::TextureDimension::kCube); + type::DepthTexture cube(type::TextureDimension::kCube); auto id_cube = b.GenerateTypeIfNeeded(&cube); ASSERT_FALSE(b.has_error()) << b.error(); @@ -570,7 +570,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_Cube) { } TEST_F(BuilderTest_Type, DepthTexture_Generate_CubeArray) { - ast::type::DepthTexture cube_array(ast::type::TextureDimension::kCubeArray); + type::DepthTexture cube_array(type::TextureDimension::kCubeArray); auto id_cube_array = b.GenerateTypeIfNeeded(&cube_array); ASSERT_FALSE(b.has_error()) << b.error(); @@ -585,7 +585,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_CubeArray) { } TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_i32) { - ast::type::MultisampledTexture ms(ast::type::TextureDimension::k2d, ty.i32); + type::MultisampledTexture ms(type::TextureDimension::k2d, ty.i32); EXPECT_EQ(1u, b.GenerateTypeIfNeeded(&ms)); ASSERT_FALSE(b.has_error()) << b.error(); @@ -595,7 +595,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_i32) { } TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_u32) { - ast::type::MultisampledTexture ms(ast::type::TextureDimension::k2d, ty.u32); + type::MultisampledTexture ms(type::TextureDimension::k2d, ty.u32); EXPECT_EQ(b.GenerateTypeIfNeeded(&ms), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -606,7 +606,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_u32) { } TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) { - ast::type::MultisampledTexture ms(ast::type::TextureDimension::k2d, ty.f32); + type::MultisampledTexture ms(type::TextureDimension::k2d, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&ms), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -617,7 +617,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) { - ast::type::SampledTexture s(ast::type::TextureDimension::k1d, ty.i32); + type::SampledTexture s(type::TextureDimension::k1d, ty.i32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -632,7 +632,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) { - ast::type::SampledTexture s(ast::type::TextureDimension::k1d, ty.u32); + type::SampledTexture s(type::TextureDimension::k1d, ty.u32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -647,7 +647,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) { - ast::type::SampledTexture s(ast::type::TextureDimension::k1d, ty.f32); + type::SampledTexture s(type::TextureDimension::k1d, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -662,7 +662,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) { - ast::type::SampledTexture s(ast::type::TextureDimension::k1dArray, ty.f32); + type::SampledTexture s(type::TextureDimension::k1dArray, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -677,7 +677,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) { - ast::type::SampledTexture s(ast::type::TextureDimension::k2d, ty.f32); + type::SampledTexture s(type::TextureDimension::k2d, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -688,7 +688,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) { - ast::type::SampledTexture s(ast::type::TextureDimension::k2dArray, ty.f32); + type::SampledTexture s(type::TextureDimension::k2dArray, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -699,7 +699,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) { - ast::type::SampledTexture s(ast::type::TextureDimension::k3d, ty.f32); + type::SampledTexture s(type::TextureDimension::k3d, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -710,7 +710,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) { - ast::type::SampledTexture s(ast::type::TextureDimension::kCube, ty.f32); + type::SampledTexture s(type::TextureDimension::kCube, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -722,7 +722,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { - ast::type::SampledTexture s(ast::type::TextureDimension::kCubeArray, ty.f32); + type::SampledTexture s(type::TextureDimension::kCubeArray, ty.f32); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); @@ -736,8 +736,8 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) { - ast::type::StorageTexture s(ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kR16Float); + type::StorageTexture s(type::TextureDimension::k1d, + type::ImageFormat::kR16Float); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -753,8 +753,8 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) { - ast::type::StorageTexture s(ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kR8Snorm); + type::StorageTexture s(type::TextureDimension::k1d, + type::ImageFormat::kR8Snorm); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -770,8 +770,8 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) { - ast::type::StorageTexture s(ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kR8Unorm); + type::StorageTexture s(type::TextureDimension::k1d, + type::ImageFormat::kR8Unorm); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -787,8 +787,8 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) { - ast::type::StorageTexture s(ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kR8Uint); + type::StorageTexture s(type::TextureDimension::k1d, + type::ImageFormat::kR8Uint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -799,8 +799,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) { - ast::type::StorageTexture s(ast::type::TextureDimension::k1d, - ast::type::ImageFormat::kR8Sint); + type::StorageTexture s(type::TextureDimension::k1d, + type::ImageFormat::kR8Sint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -811,8 +811,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_array) { - ast::type::StorageTexture s(ast::type::TextureDimension::k1dArray, - ast::type::ImageFormat::kR16Float); + type::StorageTexture s(type::TextureDimension::k1dArray, + type::ImageFormat::kR16Float); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -828,8 +828,8 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { - ast::type::StorageTexture s(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR16Float); + type::StorageTexture s(type::TextureDimension::k2d, + type::ImageFormat::kR16Float); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -840,8 +840,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { - ast::type::StorageTexture s(ast::type::TextureDimension::k2dArray, - ast::type::ImageFormat::kR16Float); + type::StorageTexture s(type::TextureDimension::k2dArray, + type::ImageFormat::kR16Float); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -852,8 +852,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { - ast::type::StorageTexture s(ast::type::TextureDimension::k3d, - ast::type::ImageFormat::kR16Float); + type::StorageTexture s(type::TextureDimension::k3d, + type::ImageFormat::kR16Float); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -865,8 +865,8 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32float) { - ast::type::StorageTexture s(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR32Float); + type::StorageTexture s(type::TextureDimension::k2d, + type::ImageFormat::kR32Float); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -878,8 +878,8 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) { - ast::type::StorageTexture s(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR32Sint); + type::StorageTexture s(type::TextureDimension::k2d, + type::ImageFormat::kR32Sint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -891,8 +891,8 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) { - ast::type::StorageTexture s(ast::type::TextureDimension::k2d, - ast::type::ImageFormat::kR32Uint); + type::StorageTexture s(type::TextureDimension::k2d, + type::ImageFormat::kR32Uint); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); @@ -903,24 +903,24 @@ TEST_F(BuilderTest_Type, } TEST_F(BuilderTest_Type, Sampler) { - ast::type::Sampler sampler(ast::type::SamplerKind::kSampler); + type::Sampler sampler(type::SamplerKind::kSampler); EXPECT_EQ(b.GenerateTypeIfNeeded(&sampler), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n"); } TEST_F(BuilderTest_Type, ComparisonSampler) { - ast::type::Sampler sampler(ast::type::SamplerKind::kComparisonSampler); + type::Sampler sampler(type::SamplerKind::kComparisonSampler); EXPECT_EQ(b.GenerateTypeIfNeeded(&sampler), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n"); } TEST_F(BuilderTest_Type, Dedup_Sampler_And_ComparisonSampler) { - ast::type::Sampler comp_sampler(ast::type::SamplerKind::kComparisonSampler); + type::Sampler comp_sampler(type::SamplerKind::kComparisonSampler); EXPECT_EQ(b.GenerateTypeIfNeeded(&comp_sampler), 1u); - ast::type::Sampler sampler(ast::type::SamplerKind::kSampler); + type::Sampler sampler(type::SamplerKind::kSampler); EXPECT_EQ(b.GenerateTypeIfNeeded(&sampler), 1u); ASSERT_FALSE(b.has_error()) << b.error(); diff --git a/src/writer/spirv/builder_unary_op_expression_test.cc b/src/writer/spirv/builder_unary_op_expression_test.cc index 5fc830b7c4..409994c2b2 100644 --- a/src/writer/spirv/builder_unary_op_expression_test.cc +++ b/src/writer/spirv/builder_unary_op_expression_test.cc @@ -20,10 +20,10 @@ #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/vector_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/vector_type.h" #include "src/ast/unary_op_expression.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index a0f2c6cb2f..c395c603e8 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -50,28 +50,28 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/float_to_string.h" namespace tint { @@ -172,15 +172,15 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, return true; } -bool GeneratorImpl::EmitConstructedType(const ast::type::Type* ty) { +bool GeneratorImpl::EmitConstructedType(const type::Type* ty) { make_indent(); - if (auto* alias = ty->As()) { + if (auto* alias = ty->As()) { out_ << "type " << module_.SymbolToName(alias->symbol()) << " = "; if (!EmitType(alias->type())) { return false; } out_ << ";" << std::endl; - } else if (auto* str = ty->As()) { + } else if (auto* str = ty->As()) { if (!EmitStructType(str)) { return false; } @@ -387,9 +387,9 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { return EmitBlockAndNewline(func->body()); } -bool GeneratorImpl::EmitImageFormat(const ast::type::ImageFormat fmt) { +bool GeneratorImpl::EmitImageFormat(const type::ImageFormat fmt) { switch (fmt) { - case ast::type::ImageFormat::kNone: + case type::ImageFormat::kNone: error_ = "unknown image format"; return false; default: @@ -398,9 +398,9 @@ bool GeneratorImpl::EmitImageFormat(const ast::type::ImageFormat fmt) { return true; } -bool GeneratorImpl::EmitType(ast::type::Type* type) { +bool GeneratorImpl::EmitType(type::Type* type) { std::string storage_texture_access = ""; - if (auto* ac = type->As()) { + if (auto* ac = type->As()) { out_ << "[[access("; if (ac->IsReadOnly()) { out_ << "read"; @@ -417,9 +417,9 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { return false; } return true; - } else if (auto* alias = type->As()) { + } else if (auto* alias = type->As()) { out_ << module_.SymbolToName(alias->symbol()); - } else if (auto* ary = type->As()) { + } else if (auto* ary = type->As()) { for (auto* deco : ary->decorations()) { if (auto* stride = deco->As()) { out_ << "[[stride(" << stride->stride() << ")]] "; @@ -435,43 +435,43 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { out_ << ", " << ary->size(); out_ << ">"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "bool"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "f32"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "i32"; - } else if (auto* mat = type->As()) { + } else if (auto* mat = type->As()) { out_ << "mat" << mat->columns() << "x" << mat->rows() << "<"; if (!EmitType(mat->type())) { return false; } out_ << ">"; - } else if (auto* ptr = type->As()) { + } else if (auto* ptr = type->As()) { out_ << "ptr<" << ptr->storage_class() << ", "; if (!EmitType(ptr->type())) { return false; } out_ << ">"; - } else if (auto* sampler = type->As()) { + } else if (auto* sampler = type->As()) { out_ << "sampler"; if (sampler->IsComparison()) { out_ << "_comparison"; } - } else if (auto* str = type->As()) { + } else if (auto* str = type->As()) { // The struct, as a type, is just the name. We should have already emitted // the declaration through a call to |EmitStructType| earlier. out_ << module_.SymbolToName(str->symbol()); - } else if (auto* texture = type->As()) { + } else if (auto* texture = type->As()) { out_ << "texture_"; - if (texture->Is()) { + if (texture->Is()) { out_ << "depth_"; - } else if (texture->Is()) { + } else if (texture->Is()) { /* nothing to emit */ - } else if (texture->Is()) { + } else if (texture->Is()) { out_ << "multisampled_"; - } else if (texture->Is()) { + } else if (texture->Is()) { out_ << "storage_"; } else { error_ = "unknown texture type"; @@ -479,25 +479,25 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { } switch (texture->dim()) { - case ast::type::TextureDimension::k1d: + case type::TextureDimension::k1d: out_ << "1d"; break; - case ast::type::TextureDimension::k1dArray: + case type::TextureDimension::k1dArray: out_ << "1d_array"; break; - case ast::type::TextureDimension::k2d: + case type::TextureDimension::k2d: out_ << "2d"; break; - case ast::type::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out_ << "2d_array"; break; - case ast::type::TextureDimension::k3d: + case type::TextureDimension::k3d: out_ << "3d"; break; - case ast::type::TextureDimension::kCube: + case type::TextureDimension::kCube: out_ << "cube"; break; - case ast::type::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out_ << "cube_array"; break; default: @@ -505,19 +505,19 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { return false; } - if (auto* sampled = texture->As()) { + if (auto* sampled = texture->As()) { out_ << "<"; if (!EmitType(sampled->type())) { return false; } out_ << ">"; - } else if (auto* ms = texture->As()) { + } else if (auto* ms = texture->As()) { out_ << "<"; if (!EmitType(ms->type())) { return false; } out_ << ">"; - } else if (auto* storage = texture->As()) { + } else if (auto* storage = texture->As()) { out_ << "<"; if (!EmitImageFormat(storage->image_format())) { return false; @@ -525,15 +525,15 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { out_ << ">"; } - } else if (type->Is()) { + } else if (type->Is()) { out_ << "u32"; - } else if (auto* vec = type->As()) { + } else if (auto* vec = type->As()) { out_ << "vec" << vec->size() << "<"; if (!EmitType(vec->type())) { return false; } out_ << ">"; - } else if (type->Is()) { + } else if (type->Is()) { out_ << "void"; } else { error_ = "unknown type in EmitType: " + type->type_name(); @@ -543,7 +543,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { return true; } -bool GeneratorImpl::EmitStructType(const ast::type::Struct* str) { +bool GeneratorImpl::EmitStructType(const type::Struct* str) { auto* impl = str->impl(); for (auto* deco : impl->decorations()) { out_ << "[["; diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index 9b25e820e4..1b3d568134 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -37,12 +37,12 @@ #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/type.h" #include "src/writer/text_generator.h" namespace tint { @@ -70,7 +70,7 @@ class GeneratorImpl : public TextGenerator { /// Handles generating a constructed type /// @param ty the constructed to generate /// @returns true if the constructed was emitted - bool EmitConstructedType(const ast::type::Type* ty); + bool EmitConstructedType(const type::Type* ty); /// Handles an array accessor expression /// @param expr the expression to emit /// @returns true if the array accessor was emitted @@ -178,15 +178,15 @@ class GeneratorImpl : public TextGenerator { /// Handles generating type /// @param type the type to generate /// @returns true if the type is emitted - bool EmitType(ast::type::Type* type); + bool EmitType(type::Type* type); /// Handles generating a struct declaration /// @param str the struct /// @returns true if the struct is emitted - bool EmitStructType(const ast::type::Struct* str); + bool EmitStructType(const type::Struct* str); /// Handles emitting an image format /// @param fmt the format to generate /// @returns true if the format is emitted - bool EmitImageFormat(const ast::type::ImageFormat fmt); + bool EmitImageFormat(const type::ImageFormat fmt); /// Handles emitting a type constructor /// @param expr the type constructor expression /// @returns true if the constructor is emitted diff --git a/src/writer/wgsl/generator_impl_alias_type_test.cc b/src/writer/wgsl/generator_impl_alias_type_test.cc index d1813ad5c2..fc158a1753 100644 --- a/src/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/writer/wgsl/generator_impl_alias_type_test.cc @@ -16,7 +16,7 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" -#include "src/ast/type/struct_type.h" +#include "src/type/struct_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_array_accessor_test.cc b/src/writer/wgsl/generator_impl_array_accessor_test.cc index 2d8a85d245..6a3e208074 100644 --- a/src/writer/wgsl/generator_impl_array_accessor_test.cc +++ b/src/writer/wgsl/generator_impl_array_accessor_test.cc @@ -19,7 +19,7 @@ #include "src/ast/identifier_expression.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_bitcast_test.cc b/src/writer/wgsl/generator_impl_bitcast_test.cc index 01c6d5ec00..7441780cf4 100644 --- a/src/writer/wgsl/generator_impl_bitcast_test.cc +++ b/src/writer/wgsl/generator_impl_bitcast_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/bitcast_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/type/f32_type.h" +#include "src/type/f32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_case_test.cc b/src/writer/wgsl/generator_impl_case_test.cc index ff2f393417..cd52219073 100644 --- a/src/writer/wgsl/generator_impl_case_test.cc +++ b/src/writer/wgsl/generator_impl_case_test.cc @@ -19,7 +19,7 @@ #include "src/ast/case_statement.h" #include "src/ast/identifier_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_cast_test.cc b/src/writer/wgsl/generator_impl_cast_test.cc index b90a7a1414..ff2881bb58 100644 --- a/src/writer/wgsl/generator_impl_cast_test.cc +++ b/src/writer/wgsl/generator_impl_cast_test.cc @@ -16,8 +16,8 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/type/f32_type.h" #include "src/ast/type_constructor_expression.h" +#include "src/type/f32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_constructor_test.cc b/src/writer/wgsl/generator_impl_constructor_test.cc index 31a577e368..4705802ffa 100644 --- a/src/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/writer/wgsl/generator_impl_constructor_test.cc @@ -17,14 +17,14 @@ #include "src/ast/float_literal.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" #include "src/ast/uint_literal.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index c8f4b864ca..21844c6a5b 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -22,13 +22,13 @@ #include "src/ast/stage_decoration.h" #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" +#include "src/type/access_control_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/void_type.h" #include "src/type_determiner.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" @@ -172,7 +172,7 @@ TEST_F(WgslGeneratorImplTest, ast::StructMemberList{Member("d", ty.f32, {MemberOffset(0)})}, s_decos); auto* s = ty.struct_("Data", str); - ast::type::AccessControl ac(ast::AccessControl::kReadWrite, s); + type::AccessControl ac(ast::AccessControl::kReadWrite, s); auto* data_var = Var("data", ast::StorageClass::kStorage, &ac, nullptr, ast::VariableDecorationList{ diff --git a/src/writer/wgsl/generator_impl_switch_test.cc b/src/writer/wgsl/generator_impl_switch_test.cc index 602fe51ece..48b2b83656 100644 --- a/src/writer/wgsl/generator_impl_switch_test.cc +++ b/src/writer/wgsl/generator_impl_switch_test.cc @@ -20,7 +20,7 @@ #include "src/ast/identifier_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" -#include "src/ast/type/i32_type.h" +#include "src/type/i32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_test.cc b/src/writer/wgsl/generator_impl_test.cc index 37f080a3f9..c3661d5101 100644 --- a/src/writer/wgsl/generator_impl_test.cc +++ b/src/writer/wgsl/generator_impl_test.cc @@ -19,7 +19,7 @@ #include "gtest/gtest.h" #include "src/ast/function.h" #include "src/ast/module.h" -#include "src/ast/type/void_type.h" +#include "src/type/void_type.h" #include "src/writer/wgsl/test_helper.h" namespace tint { diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index cff995dab0..f67e8ebcfe 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -21,22 +21,22 @@ #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/type/access_control_type.h" -#include "src/ast/type/array_type.h" -#include "src/ast/type/bool_type.h" -#include "src/ast/type/depth_texture_type.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/matrix_type.h" -#include "src/ast/type/multisampled_texture_type.h" -#include "src/ast/type/pointer_type.h" -#include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/sampler_type.h" -#include "src/ast/type/storage_texture_type.h" -#include "src/ast/type/struct_type.h" -#include "src/ast/type/u32_type.h" -#include "src/ast/type/vector_type.h" -#include "src/ast/type/void_type.h" +#include "src/type/access_control_type.h" +#include "src/type/array_type.h" +#include "src/type/bool_type.h" +#include "src/type/depth_texture_type.h" +#include "src/type/f32_type.h" +#include "src/type/i32_type.h" +#include "src/type/matrix_type.h" +#include "src/type/multisampled_texture_type.h" +#include "src/type/pointer_type.h" +#include "src/type/sampled_texture_type.h" +#include "src/type/sampler_type.h" +#include "src/type/storage_texture_type.h" +#include "src/type/struct_type.h" +#include "src/type/u32_type.h" +#include "src/type/vector_type.h" +#include "src/type/void_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" @@ -68,7 +68,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_AccessControl_Read) { create(ast::StructMemberList{Member("a", ty.i32)}, decos); auto* s = ty.struct_("S", str); - ast::type::AccessControl a(ast::AccessControl::kReadOnly, s); + type::AccessControl a(ast::AccessControl::kReadOnly, s); ASSERT_TRUE(gen.EmitType(&a)) << gen.error(); EXPECT_EQ(gen.result(), "[[access(read)]]\nS"); @@ -83,35 +83,35 @@ TEST_F(WgslGeneratorImplTest, EmitType_AccessControl_ReadWrite) { create(ast::StructMemberList{Member("a", ty.i32)}, decos); auto* s = ty.struct_("S", str); - ast::type::AccessControl a(ast::AccessControl::kReadWrite, s); + type::AccessControl a(ast::AccessControl::kReadWrite, s); ASSERT_TRUE(gen.EmitType(&a)) << gen.error(); EXPECT_EQ(gen.result(), "[[access(read_write)]]\nS"); } TEST_F(WgslGeneratorImplTest, EmitType_Array_Decoration) { - ast::type::Array a(ty.bool_, 4, - ast::ArrayDecorationList{ - create(16u), - }); + type::Array a(ty.bool_, 4, + ast::ArrayDecorationList{ + create(16u), + }); ASSERT_TRUE(gen.EmitType(&a)) << gen.error(); EXPECT_EQ(gen.result(), "[[stride(16)]] array"); } TEST_F(WgslGeneratorImplTest, EmitType_Array_MultipleDecorations) { - ast::type::Array a(ty.bool_, 4, - ast::ArrayDecorationList{ - create(16u), - create(32u), - }); + type::Array a(ty.bool_, 4, + ast::ArrayDecorationList{ + create(16u), + create(32u), + }); ASSERT_TRUE(gen.EmitType(&a)) << gen.error(); EXPECT_EQ(gen.result(), "[[stride(16)]] [[stride(32)]] array"); } TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { - ast::type::Array a(ty.bool_, 0, ast::ArrayDecorationList{}); + type::Array a(ty.bool_, 0, ast::ArrayDecorationList{}); ASSERT_TRUE(gen.EmitType(&a)) << gen.error(); EXPECT_EQ(gen.result(), "array"); @@ -138,7 +138,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix) { } TEST_F(WgslGeneratorImplTest, EmitType_Pointer) { - ast::type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); + type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup); ASSERT_TRUE(gen.EmitType(&p)) << gen.error(); EXPECT_EQ(gen.result(), "ptr"); @@ -207,7 +207,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Void) { } struct TextureData { - ast::type::TextureDimension dim; + type::TextureDimension dim; const char* name; }; inline std::ostream& operator<<(std::ostream& out, TextureData data) { @@ -219,7 +219,7 @@ using WgslGenerator_DepthTextureTest = TestParamHelper; TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) { auto param = GetParam(); - ast::type::DepthTexture d(param.dim); + type::DepthTexture d(param.dim); ASSERT_TRUE(gen.EmitType(&d)) << gen.error(); EXPECT_EQ(gen.result(), param.name); @@ -228,18 +228,17 @@ INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_DepthTextureTest, testing::Values( - TextureData{ast::type::TextureDimension::k2d, "texture_depth_2d"}, - TextureData{ast::type::TextureDimension::k2dArray, - "texture_depth_2d_array"}, - TextureData{ast::type::TextureDimension::kCube, "texture_depth_cube"}, - TextureData{ast::type::TextureDimension::kCubeArray, + TextureData{type::TextureDimension::k2d, "texture_depth_2d"}, + TextureData{type::TextureDimension::k2dArray, "texture_depth_2d_array"}, + TextureData{type::TextureDimension::kCube, "texture_depth_cube"}, + TextureData{type::TextureDimension::kCubeArray, "texture_depth_cube_array"})); using WgslGenerator_SampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { auto param = GetParam(); - ast::type::SampledTexture t(param.dim, ty.f32); + type::SampledTexture t(param.dim, ty.f32); ASSERT_TRUE(gen.EmitType(&t)) << gen.error(); EXPECT_EQ(gen.result(), std::string(param.name) + ""); @@ -248,7 +247,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { auto param = GetParam(); - ast::type::SampledTexture t(param.dim, ty.i32); + type::SampledTexture t(param.dim, ty.i32); ASSERT_TRUE(gen.EmitType(&t)) << gen.error(); EXPECT_EQ(gen.result(), std::string(param.name) + ""); @@ -257,7 +256,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) { auto param = GetParam(); - ast::type::SampledTexture t(param.dim, ty.u32); + type::SampledTexture t(param.dim, ty.u32); ASSERT_TRUE(gen.EmitType(&t)) << gen.error(); EXPECT_EQ(gen.result(), std::string(param.name) + ""); @@ -266,20 +265,19 @@ INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_SampledTextureTest, testing::Values( - TextureData{ast::type::TextureDimension::k1d, "texture_1d"}, - TextureData{ast::type::TextureDimension::k1dArray, "texture_1d_array"}, - TextureData{ast::type::TextureDimension::k2d, "texture_2d"}, - TextureData{ast::type::TextureDimension::k2dArray, "texture_2d_array"}, - TextureData{ast::type::TextureDimension::k3d, "texture_3d"}, - TextureData{ast::type::TextureDimension::kCube, "texture_cube"}, - TextureData{ast::type::TextureDimension::kCubeArray, - "texture_cube_array"})); + TextureData{type::TextureDimension::k1d, "texture_1d"}, + TextureData{type::TextureDimension::k1dArray, "texture_1d_array"}, + TextureData{type::TextureDimension::k2d, "texture_2d"}, + TextureData{type::TextureDimension::k2dArray, "texture_2d_array"}, + TextureData{type::TextureDimension::k3d, "texture_3d"}, + TextureData{type::TextureDimension::kCube, "texture_cube"}, + TextureData{type::TextureDimension::kCubeArray, "texture_cube_array"})); using WgslGenerator_MultiampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { auto param = GetParam(); - ast::type::MultisampledTexture t(param.dim, ty.f32); + type::MultisampledTexture t(param.dim, ty.f32); ASSERT_TRUE(gen.EmitType(&t)) << gen.error(); EXPECT_EQ(gen.result(), std::string(param.name) + ""); @@ -288,7 +286,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { auto param = GetParam(); - ast::type::MultisampledTexture t(param.dim, ty.i32); + type::MultisampledTexture t(param.dim, ty.i32); ASSERT_TRUE(gen.EmitType(&t)) << gen.error(); EXPECT_EQ(gen.result(), std::string(param.name) + ""); @@ -297,7 +295,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { auto param = GetParam(); - ast::type::MultisampledTexture t(param.dim, ty.u32); + type::MultisampledTexture t(param.dim, ty.u32); ASSERT_TRUE(gen.EmitType(&t)) << gen.error(); EXPECT_EQ(gen.result(), std::string(param.name) + ""); @@ -305,12 +303,12 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest, WgslGenerator_MultiampledTextureTest, testing::Values(TextureData{ - ast::type::TextureDimension::k2d, + type::TextureDimension::k2d, "texture_multisampled_2d"})); struct StorageTextureData { - ast::type::ImageFormat fmt; - ast::type::TextureDimension dim; + type::ImageFormat fmt; + type::TextureDimension dim; ast::AccessControl access; const char* name; }; @@ -322,8 +320,8 @@ using WgslGenerator_StorageTextureTest = TestParamHelper; TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { auto param = GetParam(); - ast::type::StorageTexture t(param.dim, param.fmt); - ast::type::AccessControl ac(param.access, &t); + type::StorageTexture t(param.dim, param.fmt); + type::AccessControl ac(param.access, &t); ASSERT_TRUE(gen.EmitType(&ac)) << gen.error(); EXPECT_EQ(gen.result(), param.name); @@ -332,53 +330,49 @@ INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_StorageTextureTest, testing::Values( - StorageTextureData{ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k1d, + StorageTextureData{type::ImageFormat::kR8Unorm, + type::TextureDimension::k1d, ast::AccessControl::kReadOnly, "[[access(read)]]\ntexture_storage_1d"}, StorageTextureData{ - ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k1dArray, + type::ImageFormat::kR8Unorm, type::TextureDimension::k1dArray, ast::AccessControl::kReadOnly, "[[access(read)]]\ntexture_storage_1d_array"}, - StorageTextureData{ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k2d, + StorageTextureData{type::ImageFormat::kR8Unorm, + type::TextureDimension::k2d, ast::AccessControl::kReadOnly, "[[access(read)]]\ntexture_storage_2d"}, StorageTextureData{ - ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k2dArray, + type::ImageFormat::kR8Unorm, type::TextureDimension::k2dArray, ast::AccessControl::kReadOnly, "[[access(read)]]\ntexture_storage_2d_array"}, - StorageTextureData{ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k3d, + StorageTextureData{type::ImageFormat::kR8Unorm, + type::TextureDimension::k3d, ast::AccessControl::kReadOnly, "[[access(read)]]\ntexture_storage_3d"}, - StorageTextureData{ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k1d, + StorageTextureData{type::ImageFormat::kR8Unorm, + type::TextureDimension::k1d, ast::AccessControl::kWriteOnly, "[[access(write)]]\ntexture_storage_1d"}, StorageTextureData{ - ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k1dArray, + type::ImageFormat::kR8Unorm, type::TextureDimension::k1dArray, ast::AccessControl::kWriteOnly, "[[access(write)]]\ntexture_storage_1d_array"}, - StorageTextureData{ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k2d, + StorageTextureData{type::ImageFormat::kR8Unorm, + type::TextureDimension::k2d, ast::AccessControl::kWriteOnly, "[[access(write)]]\ntexture_storage_2d"}, StorageTextureData{ - ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k2dArray, + type::ImageFormat::kR8Unorm, type::TextureDimension::k2dArray, ast::AccessControl::kWriteOnly, "[[access(write)]]\ntexture_storage_2d_array"}, - StorageTextureData{ast::type::ImageFormat::kR8Unorm, - ast::type::TextureDimension::k3d, + StorageTextureData{type::ImageFormat::kR8Unorm, + type::TextureDimension::k3d, ast::AccessControl::kWriteOnly, "[[access(write)]]\ntexture_storage_3d"})); struct ImageFormatData { - ast::type::ImageFormat fmt; + type::ImageFormat fmt; const char* name; }; inline std::ostream& operator<<(std::ostream& out, ImageFormatData data) { @@ -397,53 +391,51 @@ INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_ImageFormatTest, testing::Values( - ImageFormatData{ast::type::ImageFormat::kR8Unorm, "r8unorm"}, - ImageFormatData{ast::type::ImageFormat::kR8Snorm, "r8snorm"}, - ImageFormatData{ast::type::ImageFormat::kR8Uint, "r8uint"}, - ImageFormatData{ast::type::ImageFormat::kR8Sint, "r8sint"}, - ImageFormatData{ast::type::ImageFormat::kR16Uint, "r16uint"}, - ImageFormatData{ast::type::ImageFormat::kR16Sint, "r16sint"}, - ImageFormatData{ast::type::ImageFormat::kR16Float, "r16float"}, - ImageFormatData{ast::type::ImageFormat::kRg8Unorm, "rg8unorm"}, - ImageFormatData{ast::type::ImageFormat::kRg8Snorm, "rg8snorm"}, - ImageFormatData{ast::type::ImageFormat::kRg8Uint, "rg8uint"}, - ImageFormatData{ast::type::ImageFormat::kRg8Sint, "rg8sint"}, - ImageFormatData{ast::type::ImageFormat::kR32Uint, "r32uint"}, - ImageFormatData{ast::type::ImageFormat::kR32Sint, "r32sint"}, - ImageFormatData{ast::type::ImageFormat::kR32Float, "r32float"}, - ImageFormatData{ast::type::ImageFormat::kRg16Uint, "rg16uint"}, - ImageFormatData{ast::type::ImageFormat::kRg16Sint, "rg16sint"}, - ImageFormatData{ast::type::ImageFormat::kRg16Float, "rg16float"}, - ImageFormatData{ast::type::ImageFormat::kRgba8Unorm, "rgba8unorm"}, - ImageFormatData{ast::type::ImageFormat::kRgba8UnormSrgb, - "rgba8unorm_srgb"}, - ImageFormatData{ast::type::ImageFormat::kRgba8Snorm, "rgba8snorm"}, - ImageFormatData{ast::type::ImageFormat::kRgba8Uint, "rgba8uint"}, - ImageFormatData{ast::type::ImageFormat::kRgba8Sint, "rgba8sint"}, - ImageFormatData{ast::type::ImageFormat::kBgra8Unorm, "bgra8unorm"}, - ImageFormatData{ast::type::ImageFormat::kBgra8UnormSrgb, - "bgra8unorm_srgb"}, - ImageFormatData{ast::type::ImageFormat::kRgb10A2Unorm, "rgb10a2unorm"}, - ImageFormatData{ast::type::ImageFormat::kRg11B10Float, "rg11b10float"}, - ImageFormatData{ast::type::ImageFormat::kRg32Uint, "rg32uint"}, - ImageFormatData{ast::type::ImageFormat::kRg32Sint, "rg32sint"}, - ImageFormatData{ast::type::ImageFormat::kRg32Float, "rg32float"}, - ImageFormatData{ast::type::ImageFormat::kRgba16Uint, "rgba16uint"}, - ImageFormatData{ast::type::ImageFormat::kRgba16Sint, "rgba16sint"}, - ImageFormatData{ast::type::ImageFormat::kRgba16Float, "rgba16float"}, - ImageFormatData{ast::type::ImageFormat::kRgba32Uint, "rgba32uint"}, - ImageFormatData{ast::type::ImageFormat::kRgba32Sint, "rgba32sint"}, - ImageFormatData{ast::type::ImageFormat::kRgba32Float, "rgba32float"})); + ImageFormatData{type::ImageFormat::kR8Unorm, "r8unorm"}, + ImageFormatData{type::ImageFormat::kR8Snorm, "r8snorm"}, + ImageFormatData{type::ImageFormat::kR8Uint, "r8uint"}, + ImageFormatData{type::ImageFormat::kR8Sint, "r8sint"}, + ImageFormatData{type::ImageFormat::kR16Uint, "r16uint"}, + ImageFormatData{type::ImageFormat::kR16Sint, "r16sint"}, + ImageFormatData{type::ImageFormat::kR16Float, "r16float"}, + ImageFormatData{type::ImageFormat::kRg8Unorm, "rg8unorm"}, + ImageFormatData{type::ImageFormat::kRg8Snorm, "rg8snorm"}, + ImageFormatData{type::ImageFormat::kRg8Uint, "rg8uint"}, + ImageFormatData{type::ImageFormat::kRg8Sint, "rg8sint"}, + ImageFormatData{type::ImageFormat::kR32Uint, "r32uint"}, + ImageFormatData{type::ImageFormat::kR32Sint, "r32sint"}, + ImageFormatData{type::ImageFormat::kR32Float, "r32float"}, + ImageFormatData{type::ImageFormat::kRg16Uint, "rg16uint"}, + ImageFormatData{type::ImageFormat::kRg16Sint, "rg16sint"}, + ImageFormatData{type::ImageFormat::kRg16Float, "rg16float"}, + ImageFormatData{type::ImageFormat::kRgba8Unorm, "rgba8unorm"}, + ImageFormatData{type::ImageFormat::kRgba8UnormSrgb, "rgba8unorm_srgb"}, + ImageFormatData{type::ImageFormat::kRgba8Snorm, "rgba8snorm"}, + ImageFormatData{type::ImageFormat::kRgba8Uint, "rgba8uint"}, + ImageFormatData{type::ImageFormat::kRgba8Sint, "rgba8sint"}, + ImageFormatData{type::ImageFormat::kBgra8Unorm, "bgra8unorm"}, + ImageFormatData{type::ImageFormat::kBgra8UnormSrgb, "bgra8unorm_srgb"}, + ImageFormatData{type::ImageFormat::kRgb10A2Unorm, "rgb10a2unorm"}, + ImageFormatData{type::ImageFormat::kRg11B10Float, "rg11b10float"}, + ImageFormatData{type::ImageFormat::kRg32Uint, "rg32uint"}, + ImageFormatData{type::ImageFormat::kRg32Sint, "rg32sint"}, + ImageFormatData{type::ImageFormat::kRg32Float, "rg32float"}, + ImageFormatData{type::ImageFormat::kRgba16Uint, "rgba16uint"}, + ImageFormatData{type::ImageFormat::kRgba16Sint, "rgba16sint"}, + ImageFormatData{type::ImageFormat::kRgba16Float, "rgba16float"}, + ImageFormatData{type::ImageFormat::kRgba32Uint, "rgba32uint"}, + ImageFormatData{type::ImageFormat::kRgba32Sint, "rgba32sint"}, + ImageFormatData{type::ImageFormat::kRgba32Float, "rgba32float"})); TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { - ast::type::Sampler sampler(ast::type::SamplerKind::kSampler); + type::Sampler sampler(type::SamplerKind::kSampler); ASSERT_TRUE(gen.EmitType(&sampler)) << gen.error(); EXPECT_EQ(gen.result(), "sampler"); } TEST_F(WgslGeneratorImplTest, EmitType_SamplerComparison) { - ast::type::Sampler sampler(ast::type::SamplerKind::kComparisonSampler); + type::Sampler sampler(type::SamplerKind::kComparisonSampler); ASSERT_TRUE(gen.EmitType(&sampler)) << gen.error(); EXPECT_EQ(gen.result(), "sampler_comparison"); diff --git a/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc b/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc index 3071b8ce21..c1c322970b 100644 --- a/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/wgsl/generator_impl_variable_decl_statement_test.cc @@ -17,9 +17,9 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/type/f32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/generator_impl_variable_test.cc b/src/writer/wgsl/generator_impl_variable_test.cc index 501c880207..9a8e9fcb6c 100644 --- a/src/writer/wgsl/generator_impl_variable_test.cc +++ b/src/writer/wgsl/generator_impl_variable_test.cc @@ -20,9 +20,9 @@ #include "src/ast/constant_id_decoration.h" #include "src/ast/group_decoration.h" #include "src/ast/location_decoration.h" -#include "src/ast/type/f32_type.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" +#include "src/type/f32_type.h" #include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/test_helper.h"